Diyorbek
Back to blog
1 min read

TypeScript Tips I Reach For Daily

Small, high-leverage TypeScript patterns that make everyday code safer and easier to read.

typescripttipstools

You don't need advanced type gymnastics to get most of TypeScript's value. These few patterns cover the majority of my day-to-day.

as const for literal unions

const sizes = ["sm", "md", "lg"] as const;
type Size = (typeof sizes)[number]; // "sm" | "md" | "lg"

satisfies to keep inference

Validate a value against a type without widening it โ€” you keep the precise literal types while still catching mistakes.

Prefer unknown over any

unknown forces you to narrow before use, which is exactly the safety you wanted.