找出深度只读类型里的 bug

来自 高级类型
TypeScript 6 高级 4分钟 找出 2处问题

找出这个生成的 DeepReadonly 工具没有正确支持的对象类型。

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());
在试验场中打开
报告错误