Skip to content

Instantly share code, notes, and snippets.

@luismisanchez
Created January 19, 2021 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luismisanchez/829bbcae60bc2bb3e73ddfa8976691c6 to your computer and use it in GitHub Desktop.
Save luismisanchez/829bbcae60bc2bb3e73ddfa8976691c6 to your computer and use it in GitHub Desktop.
Typescript Generics
// Generics are types which can hold/ use several types
// We're only touching the very basics here - you can go MUCH more into detail
// Consider the Array object
let numberArray: Array<number>; // This array will only accept numbers
// Try to initialize it with strings
// numberArray = ['test']; // => Error
numberArray = [1,2,3];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment