Skip to content
Justice Tech School

as const

as const makes values readonly literals, great for lookup tables and tuples.

Example
const routes = { home: "/", about: "/about" } as const;
type R = typeof routes[keyof typeof routes];
const r: R = "/about";
console.log(r);

Result

/about

Exercise

Freeze literals.

{ a: 1 } as 

Quiz Test

What does as const do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.