Literal Types and const Assertions
A literal type allows only one exact value. as const makes an object deeply readonly with literal types, handy for configuration and lookups.
Example
type Dir = "up" | "down" | "left" | "right";
const moves: Dir[] = ["up", "left"];
const config = { mode: "dark", sizes: [1, 2] } as const;
console.log(moves, config.mode, config.sizes.length);Result
[ "up", "left" ] dark 2
Exercise
Freeze with literal types.
const c = { a: 1 } const;
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.