Literal Type
A literal type is a value, enforced as a type.
That means, a variable of literal type can only have value of the Literal and nothing else.
You can say it is a subtype of a primitive data type. While primitive data types allow a range of values, literal narrows it down to specific predifined value (values in some cases).
For example:
let iamlit: "Hello"; //"Hello" is literal type
iamlit = "Hello"; //OK
iamlit = "Bounjor" //Error
Here iamlit
can only have value of the literal.
Backlinks