Mutable Keys
提出詳細
type MyEqual<X,Y> = (<T>() => T extends X ? 0 : 1) extends (<U>() => U extends Y ? 0 : 1) ? true : false type IsMutable<T,K extends keyof T> = MyEqual<Pick<T,K>,Readonly<Pick<T,K>>> extends true ? false : true type MutableKeys<T,K extends keyof T=keyof T> = K extends K ? IsMutable<T,K> extends true ? K : never : never
提出日時 | 2023-09-22 16:08:15 |
---|---|
問題 | Mutable Keys |
ユーザー | sankantsu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<MutableKeys<{ a: number; readonly b: string }>, 'a'>>, Expect<Equal<MutableKeys<{ a: undefined; readonly b: undefined }>, 'a'>>, Expect<Equal<MutableKeys<{ a: undefined; readonly b?: undefined; c: string; d: null }>, 'a' | 'c' | 'd'>>, Expect<Equal<MutableKeys<{}>, never>>, ]