Write DeepReadonly<T>: make every nested property and array readonly, but keep functions callable.
type DeepReadonly<T> = Readonly<T>; // only the top level is readonly type Settings = { theme: { color: string; sizes: number[] }; onSave: (value: string) => void;}; // const settings: DeepReadonly<Settings>// settings.theme.color = "red"; // should be an error// settings.theme.sizes.push(1); // should be an error// settings.onSave("draft"); // should still workThe answer
Write it yourself first. Then compare it with a reference solution and the checks it passes.
Checking your sign-in…