TypeScript 类型注解和类型推断

type annotation 类型注解

let count: number;
count = 1;

type inference 类型推断

const one = 1;
const two = 2;
const three = one + two;

const person = {
  name: "张三",
  age: 45,
};

使用:

  • 如果 TS 能够自动分析变量类型, 我们就什么也不需要做了
  • 如果 TS 无法分析变量类型的话, 我们就需要使用类型注解

参考:
技术胖——TypeScript从入门到精通(04. TypeScript 类型注解和类型推断)

posted @ 2020-12-23 16:02  qianbuhan  阅读(703)  评论(0)    收藏  举报