TypeScript 7 · Types

Make a literal read-only

Infer the narrowest literal types and make properties readonly.

const routes = ["/home", "/about"] as const;
type Route = (typeof routes)[number];

Official TypeScript 7 documentation

More types commands

All types commands · TypeScript 7 cheatsheet

Was this page helpful?