Spot the bug in the generic JSON decoder

from Generics
TypeScript 6 intermediate 4 min 1 issue to find

Find the false guarantee in this generated generic JSON helper.

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());
Open in playground
Report an error