TypeScript in real projects · mid
satisfies, as const, enums and assertions
as const keeps literal types and makes values readonly, satisfies checks a value against a type without widening it, and as assertions skip checks, so they are the last resort.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
const x = { mode: 'dark' } as constgivesmode: 'dark'(readonly), notstring.const routes = {...} satisfies Record<string, Route>errors on bad entries but keeps the exact keys for autocomplete.x as Usertells the compiler to trust you: no check, a common source of runtime bugs. Prefer narrowing or validation.- Enums emit runtime code and numeric enums accept any number; a union of string literals (or an
as constobject) is usually better.erasableSyntaxOnly(TS 5.8) bans enums for type-stripping runtimes like Node.
The red pen
Common traps: mistake → fix
Mistake: "satisfies is the same as a type annotation"
Fix: an annotation widens the value to the type; satisfies keeps the narrower inferred type.
Mistake: "as converts the value"
Fix: it changes nothing at runtime.
Easy to hard
Questions interviewers ask, easy to hard
- When do you use satisfies over an annotation?
- Why do many teams avoid enums?
- When is an
asassertion acceptable?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.