Sharpen your understanding of TypeScript's satisfies operator, const generic parameters, and NoInfer — three modern features that give you type safety without sacrificing type narrowing.
0 / 5 completed
1 / 5
What problem does the TypeScript satisfies operator solve compared to a type annotation?
The satisfies operator checks type compatibility without widening the value's type. With const palette = { red: [255,0,0] } satisfies Record<string, number[]>, TypeScript still knows palette.red is a tuple, whereas a plain annotation would widen it to number[].
2 / 5
What does adding const to a generic type parameter (e.g., function f<const T>) do in TypeScript?
Const type parameters tell TypeScript to infer the argument with as const semantics. Without it, f(['a', 'b']) would infer T = string[]; with <const T> it infers T = ['a', 'b'], preserving tuple and literal types inside the generic.
3 / 5
What is the purpose of the NoInfer<T> utility type in TypeScript?
NoInfer<T> wraps a type parameter to exclude that position from inference. For example function setDefault<T>(items: T[], fallback: NoInfer<T>) forces T to be inferred from items alone, so fallback must match that inferred type rather than influencing it.
4 / 5
Which statement best describes when to use satisfies instead of as?
satisfies is type-safe: it errors if the value doesn't actually conform to the type. as is an assertion that silences errors regardless of correctness. Prefer satisfies for validation + narrowing; reserve as for cases where you have knowledge TypeScript can't verify.
5 / 5
Given const config = { port: 3000, host: 'localhost' } satisfies ServerConfig;, what type does config.port have?
Because satisfies does not widen the inferred type, config.port retains the literal type 3000 rather than being broadened to number. If ServerConfig required port: number, the check still passes while the literal type is preserved for downstream narrowing.