Skip to content

Latest commit

 

History

History
85 lines (58 loc) · 977 Bytes

File metadata and controls

85 lines (58 loc) · 977 Bytes

typelab / utils / ObjectRequired

type ObjectRequired<T, Key, IncludeUndefined> = _ObjectRequired<T, Key, IncludeUndefined>;

Extended TypeScript `Required` to enforce specific properties as required.

Type Parameters

Type Parameter Default type Description

T

The original object type.

Key extends keyof T

The keys of T that should be required.

IncludeUndefined extends boolean

false

Include undefined type from T[Key], defaults to false.

Returns

A type with the specified keys of T set as required.

Example

type Obj = { a?: string; b?: string };

// { a: string; b?: string }
type RequiredObj = ObjectRequired<Obj, 'a'>;