Answer the question
In order to leave comments, you need to log in
What is the difference between primitive types and literal types?
TypeScript has primitive data types called literal data types. As the name suggests, types are expressed as value literals of primitive types.
Answer the question
In order to leave comments, you need to log in
If a value is assigned to a type, it becomes a literal type.
type CarNames = 'bmw' | 'mercedes';
const cars: CarNames[] = ['bmw', 'mercedes', 'zhiguli'];
// ^^^^^^^
// TypeError: Type '"zhiguli"' is not assignable to type 'CarNames'.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question