Skip to content

webshrine / stdtyp/src / Optional

Type Alias: Optional<T, K>

Optional<T, K>: Omit<T, K> & Partial<Pick<T, K>>

Optional

Type Parameters

T extends object

K extends keyof T = keyof T

Desc

From T make a set of properties by key K become optional

Example

ts
type Props = {
     name: string;
     age: number;
     visible: boolean;
   };

   // Expect: { name?: string; age?: number; visible?: boolean; }
   type Props = Optional<Props>;

   // Expect: { name: string; age?: number; visible?: boolean; }
   type Props = Optional<Props, 'age' | 'visible'>;

Defined in

node_modules/.pnpm/utility-types@3.11.0/node_modules/utility-types/dist/mapped-types.d.ts:451