1.安装TypeScript
npm install -g typescript
编译一个TypeScript 文件
tsc hello.ts
2.将以下代码 写入到 hello.ts 中
1 | function sayHello(person:string) { |
然后执行
tsc hello.ts
这时候会生成一个编译好的文件 hello.js
1 | function sayHello(person) { |
- TypeScript 使用
:指定变量的类型 - TypeScript 只会进行静态检查,如果发现有错误,编译的时候就会报错