type MaybeUser = { id: string } | null | undefined;
type User = NonNullable<MaybeUser>;Useful after validation or guard logic has removed nullable cases.
Built-in utility types and practical application patterns.
Reusable helpers for app code and API modeling.
type MaybeUser = { id: string } | null | undefined;
type User = NonNullable<MaybeUser>;Useful after validation or guard logic has removed nullable cases.
type Shape = "circle" | "square" | 42;
type StringShape = Extract<Shape, string>;Helpful when refining broad unions into a specific subset.
type Shape = "circle" | "square" | 42;
type NumericFree = Exclude<Shape, number>;`Exclude` is the inverse of `Extract` and useful for filtering unions.
type Fn = (id: string, active: boolean) => void;
type FnArgs = Parameters<Fn>; // [id: string, active: boolean]Great for wrappers, event helpers, and higher-order functions.
class UserService {}
type UserServiceInstance = InstanceType<typeof UserService>;Useful in dependency injection helpers or factory utilities.
Patterns for strongly typed forms, APIs, and state machines.
type Paginated<T> = {
items: T[];
total: number;
page: number;
pageSize: number;
};A generic wrapper keeps API contracts DRY across entities.
type FieldErrors<T> = Partial<Record<keyof T, string>>;This pattern works well for forms, settings pages, and API validation results.
type AsyncState<T> =
| { status: "idle" }
| { status: "loading" }
| { status: "success"; data: T }
| { status: "error"; error: string };Discriminated unions make UI rendering branches easier to reason about.
type Events = {
"user.created": { id: string };
"user.deleted": { id: string };
};A typed event map pairs well with `keyof` and indexed access helpers.