Last active
March 23, 2020 15:34
-
-
Save PranavBhatia/79c585cb0f984079966427f3cf08cc92 to your computer and use it in GitHub Desktop.
A very basic example of generics using typescript.
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 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