Skip to content

Instantly share code, notes, and snippets.

@PranavBhatia
Last active March 23, 2020 15:34
Show Gist options
  • Save PranavBhatia/79c585cb0f984079966427f3cf08cc92 to your computer and use it in GitHub Desktop.
Save PranavBhatia/79c585cb0f984079966427f3cf08cc92 to your computer and use it in GitHub Desktop.
A very basic example of generics using typescript.
// Generics are types which can hold/use several types
let employeeNamesArray: Array<string>; // This array will only accept strings
// employeeNamesArray = [123]; // => Error
employeeNamesArray = ['Bob', 'Sam'];
console.log(employeeNamesArray); // Result => [ 'Bob', 'Sam' ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment