Last active
February 11, 2019 06:23
-
-
Save LFSCamargo/6cce80fce2ef8d810dd15a3bce129222 to your computer and use it in GitHub Desktop.
Generics example using flow or ts
This file contains 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
// Generics type & interface | |
type HasGeneric<T> = { | |
genericType: T, | |
nonGenericType: string, | |
arrayGeneric: Array<T>, | |
} | |
interface GenericsInterface<T> { | |
genericType: T; | |
nonGenericType: string; | |
arrayGeneric: Array<T>; | |
} | |
// Multiple generics example | |
type MultipleGenericTypes<A, B> = { | |
genericA: A, | |
genericB: Array<B>, | |
} | |
// Generics and functions | |
function identity<T>(value: T): T { | |
return value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment