Created
June 21, 2021 03:18
-
-
Save pjlsergeant/db677a9d6f0af90ba330be7c402d598f to your computer and use it in GitHub Desktop.
A comprehensive 5-line introduction to generics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wrapP = <T>( x: T ) : Promise<T> => Promise.resolve(x); | |
const wrapL = <T>( x: T ) : T[] => [x]; | |
const foo = wrapP("string"); // Promise<string> | |
const bar = wrapL(5); // number[] | |
// PS: you can also add constraints |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment