Skip to content

Instantly share code, notes, and snippets.

@LFSCamargo
Last active February 11, 2019 06:23
Show Gist options
  • Save LFSCamargo/6cce80fce2ef8d810dd15a3bce129222 to your computer and use it in GitHub Desktop.
Save LFSCamargo/6cce80fce2ef8d810dd15a3bce129222 to your computer and use it in GitHub Desktop.
Generics example using flow or ts
// 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