Skip to content

Instantly share code, notes, and snippets.

@nulltier
Last active July 20, 2019 22:17
Show Gist options
  • Save nulltier/6febb0b282233ddcd6a32e329fb7b326 to your computer and use it in GitHub Desktop.
Save nulltier/6febb0b282233ddcd6a32e329fb7b326 to your computer and use it in GitHub Desktop.
TypeScript snippets
/*
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