找出资料格式化里的 bug

来自 类型覆盖率
TypeScript 6 进阶 4分钟 找出 2处问题

找出这个高覆盖率的资料格式化函数为何仍会在运行时失败。

TypeScript
type Profile = {
  name: string;
};

function displayName(raw: string): string {
  const profile = JSON.parse(raw) as Profile;
  return profile.name.toUpperCase();
}

console.log(displayName('{"name":null}'));
在试验场中打开
报告错误