Today I Learned…
TypeScript has String Literal Types, which lets you specify what string value is allowed for a variable.
You can specify the allowed literal values during type declaration.
When you have dozens of strings to allow with possibility to grow, adding it isn’t maintainable and error prone.
TypeScript provides keyof operator to extract keys of a type to restrict assignable values.
Let me show you how it can be used and a limitation thereof.