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