Babel 还是 tsc
- 构建后的输出和输入文件一样,就是用
tsc - 需要一个构建管道来输出多个时,就用
babel转译,tsc用来检查类型
Babel用来转译,tsc用来类型检查
使用Babel的preset-typescript来生成js文件,然后使用ts来做类型检查和生成.d.ts文件的工作。
类型检查和.d.ts文件的生成
生成.d.ts文件
tsconfig.json
"compilerOptions": {
// Ensure that .d.ts files are created by tsc, but not .js files
"declaration": true,
"emitDeclarationOnly": true,
// Ensure that Babel can safely transpile files in the TypeScript project
"isolatedModules": true
}