0% done with TypeScript: The Vue Parts
10:11
|
Published on
5/5/2020
|
|
Generics
Generics keep a type constant throughout your code but don’t specify the exact type. They’re a useful way to make your functions, interfaces, and types more reusable without losing TypeScript’s benefits.
The “hello world” of Generics is the Identity function - it just returns what it gets as an argument.
To make Generics more practical, we must do one of two things: Set constraints on what the Generic Type can be Specify the structure of your data, without constraining the Type
We show toy examples of both, and then show an example from the Vue 3 source code.
After this video, you should be able to decipher most TypeScript code.
Handbook Docs https://www.typescriptlang.org/docs/handbook/generics.html
Vue 3 Example
What do others think of VueScreencasts?
"Thank you for putting in the effort to make these videos and share with all!"
—Ritika Singh
"EXCELLENT video series so far!"
—D Durham
"Thank you, this video helped me a LOT"
—exception360
"<3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3"
—Aymen Oppa Software