Readonly 2
提出詳細
type MyReadonly2<T, K extends keyof T = any> = { readonly [U in keyof T as U extends K ? U : never]: T[U] } & // ① K に該当するプロパティだけを抽出 し readonly にする { [U in keyof T as U extends K ? never : U]: T[U] } // ② K に該当しないプロパティだけを抽出
提出日時 | 2023-08-31 14:12:38 |
---|---|
問題 | Readonly 2 |
ユーザー | snaka |
ステータス | Accepted |
import type { Alike, Expect } from '@type-challenges/utils' type cases = [ Expect<Alike<MyReadonly2<Todo1>, Readonly<Todo1>>>, Expect<Alike<MyReadonly2<Todo1, 'title' | 'description'>, Expected>>, Expect<Alike<MyReadonly2<Todo2, 'title' | 'description'>, Expected>>, ] interface Todo1 { title: string description?: string completed: boolean } interface Todo2 { readonly title: string description?: string completed: boolean } interface Expected { readonly title: string readonly description?: string completed: boolean }