这里记录一些常用的 ts config。

strictNullChecks

"strictNullChecks": true 严格区分 undefined 和 null

let weight: number | undefined
weight = undefined
// ?相当于 string | undefined
function getPeople(params: string) {
  return name || ''
}
// getPeople(null) X

moduleResolution

"moduleResolution": "node" 首先取 nodemodules 寻找模块

import _ from 'lodash'

esModuleInterop

"esModuleInterop": true

自动检测模块类型 commonjs | esmodule,与编译有关,若导出没有 default 自动加上 default

noImplicitAny

"noImplicitAny": true 不允许存在隐式的 any 类型

const student = []
const key = 'name'
// student[key] = 'zhangsan' X

相关文章:

  • 2021-10-13
  • 2021-07-27
  • 2021-08-18
  • 2021-10-02
  • 2021-12-10
  • 2021-09-01
  • 2022-12-23
猜你喜欢
  • 2021-09-08
  • 2021-07-05
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
  • 2022-12-23
  • 2021-04-26
相关资源
相似解决方案