TypeScript 的安装与使用

npm i typescript -g

依赖会安装 tsc 命令

tsc -v

初始化 配置

tsc --init

生成 tsconfig.json

tsconfig.json 配置

要支持 import 模块语法的话

  1. rollup的配置
    target 选项需要设置 ES5
    module 选项需要改成 es2015

  2. esbuild 的配置
    target: ESNext
    module: ESNext
    moduleResolution: node

严格模式 “strict”

“strict”: true,
void 类型不允许被赋值 null
null undefined 类型不允许相互赋值

转化为 js

tsc xx.ts
# 监听变化并转化 (必须先进行 ts 配置)
tsc -w

ts-node

直接执行 ts 文件
一步执行(转化再node运行)

你可能感兴趣的:(#,TypeScript,typescript,javascript,前端)