Type Challenges Judge

Deep Readonly

提出詳細

type IsPrimitive<T> = T extends number | boolean | string ? true : false type IsFunction<T> = T extends (...args: any[]) => any ? true : false type DeepReadonly<T> = { readonly [K in keyof T]: IsPrimitive<T[K]> extends true ? T[K] : IsFunction<T[K]> extends true ? T[K] : DeepReadonly<T[K]>; }
提出日時2023-08-10 01:31:56
問題Deep Readonly
ユーザーtekihei2317
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<DeepReadonly<X>, Expected>>, ] type X = { a: () => 22 b: string c: { d: boolean e: { g: { h: { i: true j: 'string' } k: 'hello' } l: [ 'hi', { m: ['hey'] }, ] } } } type Expected = { readonly a: () => 22 readonly b: string readonly c: { readonly d: boolean readonly e: { readonly g: { readonly h: { readonly i: true readonly j: 'string' } readonly k: 'hello' } readonly l: readonly [ 'hi', { readonly m: readonly ['hey'] }, ] } } }