找出泛型 JSON 解码器里的 bug

来自 泛型
TypeScript 6 进阶 4分钟 找出 1处问题

找出这个生成的泛型 JSON 辅助函数作出的虚假保证。

TypeScript
function decode<T>(raw: string): T {
  return JSON.parse(raw) as T;
}

type Account = { id: string; active: boolean };
const account = decode<Account>('{"active":"yes"}');
console.log(account.id.toLowerCase());
在试验场中打开
报告错误