Type alias RequiredKeys<T>

RequiredKeys<T>: {
    [K in keyof T]-?: {} extends {
            [P in K]: T[K]
        }
        ? never
        : K
}[keyof T]

找出required属性

跟OptionalKeys相反

Type Parameters

  • T

Example

type T = RequiredKeys<{ a: string; b?: number; c: boolean }>; // 'a'|'c'