Created
January 9, 2019 00:30
-
-
Save robertcoopercode/a4d8d492015bccf762fd2452704b1e12 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const fillArray = <T>(len: number, elem: T) => { | |
return new Array<T>(len).fill(elem); | |
}; | |
const newArray = fillArray<string>(3, 'hi'); // => ['hi', 'hi', 'hi'] | |
newArray.push('bye'); // ✅ | |
newArray.push(true); // ❌ - only strings can be added to the array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment