Literal Types
A literal type allows only exact values. Combine with unions for fixed choices.
Example
type Dir = "up" | "down";
function go(d: Dir) { return "going " + d; }
console.log(go("up"));Result
going up
Exercise
Only allow "on" or "off".
type S = "on" | ;
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.