Deep Readonly
提出詳細
type DeepReadonly<T> = { readonly [U in keyof T]: T[U] extends object ? T[U] extends (...args: any[]) => any ? T[U] : DeepReadonly<T[U]> : T[U] }
提出日時 | 2023-08-31 14:46:38 |
---|---|
問題 | Deep Readonly |
ユーザー | snaka |
ステータス | 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'] }, ] } } }