(注:开发工具 webstorm 运行代码工具 node.js typescript 基础知识用node.js来运行)
TypeScript 是 JavaScript 的一个超集
安装 typescript 工具包 在编辑器终端执行命令:
npm install -g typescript
创建第一个 ts 文件
在文件夹中创建code文件,
选择编辑器打开此文件
在编辑器中新建hello.ts文件
在终端中执行 tsc hello.ts 会生成一个hello.js 文件
node hello.js 运行hello.ts的代码
简化运行步骤:
npm install -g ts-node
安装成功
//运行代码:
// 一般步骤
//需要tsc hello.ts转成js格式,生成js文件
tsc hello.ts //先转成js
node hello.js //再运行代码
//简化步骤:
//不需要js文件
ts-node hello.ts