Spot the bug in DeepReadonly

from Advanced types
TypeScript 6 advanced 4 min 2 issues to find

Find the unsupported object cases in this generated DeepReadonly utility.

TypeScript
type DeepReadonly<Value> = Value extends object
  ? { readonly [Key in keyof Value]: DeepReadonly<Value[Key]> }
  : Value;

type Settings = {
  updatedAt: Date;
  onChange: (theme: string) => void;
  tags: string[];
};

declare const settings: DeepReadonly<Settings>;
settings.onChange("dark");
console.log(settings.updatedAt.getTime());
Open in playground
Report an error