下载
npm install -g typescript
值得注意的是:不会在每个项目都生成node_modules占磁盘空间!
这样就能全局地使用tsc命令了!
生成tsconfig.json
tsc --init
同样不会生成node_modules占磁盘空间!
编译运行
注意,官方文档已经指出,这种方式会忽略tsconfig.json!
tsc helloworld.ts
node helloworld.js
事实上,直接在项目根目录下输入
tsc
即可。
报错:重复的函数实现
两个同名函数,明明在不同的ts文件,却要报错error TS2393: Duplicate function implementation.
解决方法很简单,如果你不需要export,只需要加上
export {}
官方文档:https://www.typescriptlang.org/docs/