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?
"Great idea man, look forward to follow along."
—Manuel Diera
"Thank you for this!!!"
—Cyrus Besabella
"Amazing content. Good job, man."
—milose
"This was EXACTLY what I needed. Informative and succinct. Thank you for taking the time to do this."
—Zara Kayn