Better

Ethan的博客,欢迎访问交流

after upgrade typescript to 4.2

项目中 typescript 升级后,意外的发现对于数组的下标访问,不做 undefined 检查了……

noUncheckedIndexedAccess

noUncheckedIndexedAccess 是 typescript 4.1 新增的属性,目的就是将是否开启交给用户去选择,而不总是进行严格检查。

如果你依旧需要进行严格检查,则在 tsconfig.json 设置如下

{
  "compilerOptions": {
    "noUncheckedIndexedAccess": true,
  }
}

资料



留言