1、TypeScript是什么?

ts官网(TypeScript: The starting point for learning TypeScript)原话是这样说的:

TypeScript is JavaScript with syntax for types.

TypeScript is a strongly typed programming language which

builds on JavaScript giving you better tooling at any scale.

意思是:typeScript是带有类型语法的JavaScript,后一句慢慢悟。为什么这么说呢?

TypeScript stands in an unusual relationship to JavaScript.

TypeScript offers all of JavaScript’s features, and an additional

layer on top of these: TypeScript’s type system.

typeScript和JavaScript是有不同寻常的关系,它包括了JavaScript的所有特性,并在顶层加了一层typeScript的类型系统。用数学集合来说:就是ts是js的超集,js是ts的子集,ts多出的东西就是类型系统。

2、TS基础知识点:

1. 类型推断(Types by Inference):

ts实战运用(TS知识点手册)(1)

当我们创建一个对象时:

const user = { name: "Hayes", id: 0, };

使用ts的interface这个对象定义:

稍后再写

,