xdash / RequireFields
Type alias: RequireFields<T, K>
RequireFields<
T
,K
>:T
&{ [P in K]-?: NonNullable<T[P]> }
Requires the specified fields K in type T.
Example
type Example = { a?: number, b?: string }
type RequiredFields = RequireFields<Example, 'a'> // { a: number, b?: string }
type RequiredFields = RequireFields<Example, 'a' | 'b'> // { a: number, b: string }
Type parameters
• T
type to require fields in
• K extends keyof T
fields to require