QuickSnip LogoA light blue logo with a thunderbolt in bracketsQuickSnip

Deep Required Type

Converts all properties of a type, including nested objects, into required.

  • helper-types
  • typedefinition
  • required

Install

npx shadcn@latest add https://quicksnip.dev/r/deep-required-type.json

This snippet is not verified yet. Review it before use, or help verify it.

Code

type DeepRequired<T> = T extends object
    ? { [K in keyof T]-?: DeepRequired<T[K]> }
    : T;

Usage

type A = {
    id?: string;
    name?: string;
    details?: {
        age?: number;
        address?: { city?: string; zip?: string };
    };
};

type RequiredA = DeepRequired<A>;
// Result: { id: string; name: string; details: { age: number; address: { city: string; zip: string }; }; }