Treat Literal Types, as const & satisfies as a model of possible JavaScript runtime values, control-flow narrowing, nullability, and exhaustive checking—not merely annotation syntax. Prefer inference and begin unsafe input as unknown.
Build a Complete Mental Model
Treat Literal Types, as const & satisfies as a model of possible JavaScript runtime values, control-flow narrowing, nullability, and exhaustive checking—not merely annotation syntax. Prefer inference and begin unsafe input as unknown.
Apply It in Production TypeScript
Type-check an original Literal Types, as const & satisfies example in strict mode, then test valid values, null/undefined, malformed API data, a new union variant, and module boundaries. Fix the contract or validation instead of silencing errors with assertions or any.
After This Lesson
type Route = { path: string; secure: boolean };
const routes = {
home: { path: '/', secure: false },
account: { path: '/account', secure: true },
} as const satisfies Record<string, Route>;
const accountPath = routes.account.path; // '/account'The object is validated while retaining precise literal types.Try It Yourself
Type-check an original Literal Types, as const & satisfies example in strict mode, then test valid values, null/undefined, malformed API data, a new union variant, and module boundaries. Fix the contract or validation instead of silencing errors with assertions or any.
Type Safety Warning
Assuming a successful TypeScript compile proves API data and runtime behavior are valid.
TypeScript Handbook — TypeScript