Created
January 14, 2019 01:18
-
-
Save robertcoopercode/e89ad136edc735992d121a3aeb723674 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 = <ArrayElementType>(len: number, elem: ArrayElementType) => { | |
return new Array<ArrayElementType>(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