TypeScript tutorialLesson 31Free preview
TS Literal Types
This lesson is part of TypeScript · All levels
Summary
The literal type limits a type only to certain values, for example just "public" or just the number 42. The value with the as const retains the literal so that the type does not expand into a common string or number. This technique makes the configuration and API much more rigorous.
Key points
- The literal union limits the list of values
- Keeping the literal value
- Without the as, the literal expands into the general type
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.