示例工程 11-template-literal-types
11-template-literal-types/03-deep-readonly/src/main.ts
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
// 演示:递归映射类型 + 函数/数组分支,构造深层只读类型
export type DeepReadonly<T> = T extends (...args: never[]) => unknown
? T
: T extends readonly (infer U)[]
? ReadonlyArray<DeepReadonly<U>>
: T extends object
? { readonly [K in keyof T]: DeepReadonly<T[K]> }
: T;
export function run(): string[] {
return [];
}