nodeJs + TypeScript solves imported modules without type declarations and repeated declarations using const

Solve the problem of using const to declare the same variable between different files, and the error cannot be re-declared block-scoped variables

解决方式: Add export{} at the end of the file
原因: nodeJs uses the commonJs specification, without the concept of esModules, tslint will not regard it as an independent scope, use export{} to make tslint think that the file is an independent scope

Solve the problem that const fs = require('fs') produces fs type as any, and there is no type hint during use

有类型声明,标准 es module 库:import * as xxxx from ''import xxx from '' 导入
有类型声明,标准 commonjs 库: import xxx = require('') 导入
没有类型声明:const xxx = require('') 导入(默认导入为 any 类型)

Guess you like

Origin blog.csdn.net/weixin_44441196/article/details/121651220