Type Challenges Judge

IsRequiredKey

提出詳細

type RequiredKeys<T> = keyof { [P in keyof T as Pick<T, P> extends Required<Pick<T, P>> ? P : never]: T[P] } type IsRequiredKey<T, K extends keyof T> = [K] extends [RequiredKeys<T>] ? true : false
提出日時2024-09-12 08:05:21
問題IsRequiredKey
ユーザーookkoouu
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<IsRequiredKey<{ a: number; b?: string }, 'a'>, true>>, Expect<Equal<IsRequiredKey<{ a: number; b?: string }, 'b'>, false>>, Expect<Equal<IsRequiredKey<{ a: number; b?: string }, 'b' | 'a'>, false>>, ]