TypeScript 简称 TS ,既是一门新语言,也是 JavaScript 的一个超集,它是在 JS 的基础上增加了一套类型系统,它支持所有的 JS 语句,为工程化开发而生,最终在编译的时候去掉类型和特有的语法,生成 JS 代码。

使用

需要先通过包管理工具安装语言依赖包,比如通过 npm

npm install -g typescript ts-node
# 查看版本号
tsc -v
  • typescript:是用 TypeScript 编程的语言依赖包
  • ts-node: 是让 Node.js 可以运行 TypeScript 的执行环境

npm 包

如果存在一些包没有默认支持 TS,可使用 @types 类型包安装:

npm install -D @types/md5

tsconfig.json

tsconfig.json 文件的作用是用来管理 TypeScript 在编译过程中的一些选项配置,无须使用 编译 中的 package.json 文件。

# 初始化
tsc --init
 
Created a new tsconfig.json with:
 
  target: es2016
  module: commonjs
  strict: true
  esModuleInterop: true
  skipLibCheck: true
  forceConsistentCasingInFileNames: true
 
 
You can learn more at https://aka.ms/tsconfig
 
# 运行
tsc