TypeScript$Type-Value-BasicTypes

70 阅读1分钟

TypeScript$Type-Value-BasicTypes

JavaScript 中的基本类型在 TypeScript 中也一样,其中 nullundefined 值得注意:

  • string
  • number
  • boolean
  • null / undefined
    • 当配置项 strictNullChecks 为 false 时,和 JavaScript 没有区别;当为 true 时,会对 null / undefined 的值做限定:如不允许获取属性等操作(nullundefined 获取属性会报错)
    • postfix ! (non-null assertion operator): console.log(x!.toFixed()); // 在变量后面加! 表示我们知道该值不为 null / undefined
  • bigint
  • symbol