November 2018
Beginner
502 pages
10h 22m
English
A variable of a string literal type can only be assigned the exact string value specified in the string literal type.
In the TypeScript playground, let's go through an example:
type Control = "Textbox";
let notes: Control;notes = "Textbox";
As we would expect, the TypeScript compiler is happy with this.
notes = "DropDown";
We get the compilation error Type '"DropDown"' is not assignable to type '"Textbox"':
Read now
Unlock full access