ts 常用配置

这里记录一些常用的 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
posted @ 2020-07-07 15:54  guangzan  阅读(404)  评论(0编辑  收藏  举报