node项目,使用typescript时,如何引用使用json文件

Again -
node项目,使用typescript时,如何引用使用json文件

​之前为了找到答案花了很多时间。为了方便和我遇到一样问题的道友,以及我日后的使用。特写一篇短文。

​答案很简单,只需要配置下tsconfig.json文件就行了,但是我很抱歉的告诉各位, 官方配置文档上找不到对应的字段

​答案出自官网的文档更新版本 Typescript2.9。
​ 即添加compilerOptions配置项"resolveJsonModule": true即可。我的tsconfig.json如下

{
  "compileOnSave": true,
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "resolveJsonModule": true,
  }
}
特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。

Tags 标签

javascriptnode.jstypescript

扩展阅读

加个好友,技术交流

1628738909466805.jpg