Problem Statement
Implement DeepReadonly<T>; discuss recursion and edge cases (functions, Map/Set).
Explanation
Idea: walk the object tree and mark every nested property as readonly. Stop at primitives and functions (functions should stay callable). For Map and Set, you usually mark the container readonly but keep element types unchanged unless you create special helpers. Beware of recursive types: add a recursion limit or accept that very deep types may be slow to check.
Code Solution
SolutionRead Only
type Primitive = string | number | boolean | bigint | symbol | null | undefined;
export type DeepReadonly<T> =
T extends Primitive | Function ? T :
T extends readonly (infer U)[] ? readonly DeepReadonly<U>[] :
{ readonly [K in keyof T]: DeepReadonly<T[K]> };
// Usage
type A = { a: { b: { c: number[] } } };
type R = DeepReadonly<A>; // all nested props and arrays become readonly