Last active
July 20, 2019 22:17
-
-
Save nulltier/6febb0b282233ddcd6a32e329fb7b326 to your computer and use it in GitHub Desktop.
TypeScript snippets
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
/* | |
The source of the solution | |
https://stackoverflow.com/questions/45251664/typescript-derive-union-type-from-tuple-array-values | |
*/ | |
const listOfLetters = ['a', 'b', 'c'] as const; | |
type Letter = typeof list[number]; // 'a'|'b'|'c'; | |
let itIsOk: Letter = 'a'; | |
let itIsNot: Letter = 'd'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment