Required Keys
提出詳細
type RequiredKeys<T> = keyof { [P in keyof T as Pick<T, P> extends Required<Pick<T, P>> ? P : never]: T[P] }
提出日時 | 2024-09-12 08:04:58 |
---|---|
問題 | Required Keys |
ユーザー | ookkoouu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<RequiredKeys<{ a: number; b?: string }>, 'a'>>, Expect<Equal<RequiredKeys<{ a: undefined; b?: undefined }>, 'a'>>, Expect<Equal<RequiredKeys<{ a: undefined; b?: undefined; c: string; d: null }>, 'a' | 'c' | 'd'>>, Expect<Equal<RequiredKeys<{}>, never>>, ]