Type Challenges Judge

Readonly 2

提出詳細

type MyReadonly2<T, K extends keyof T = keyof T> = { // まずKの内容に対してreadonlyを作成する readonly [key in K]: T[key] } & { // それ以外の要素に対しては普通にkey: valueを作成する [key in keyof T as key extends K ? never : key]: T[key] }
提出日時2022-07-13 06:43:45
問題Readonly 2
ユーザーaa-0921
ステータス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 }