TypeScript 入门
环境配置
-
安装编译 TS 的工具包
npm i -g typescript
验证是否安装成功
tsc -v
-
编译并运行 ts 代码 在终端输入 tsc 文件名.ts 进行编译 然后运行 node 文件名.js
-
简化运行 ts 使用 ts-node 包,直接在 Node.js 中运行 TS 代码
npm i -g ts-node
ts-node hello.ts
大约 12 分钟
安装编译 TS 的工具包
npm i -g typescript
验证是否安装成功 tsc -v
编译并运行 ts 代码 在终端输入 tsc 文件名.ts 进行编译 然后运行 node 文件名.js
简化运行 ts
使用 ts-node 包,直接在 Node.js 中运行 TS 代码
npm i -g ts-node
ts-node hello.ts