为什么使用typescript的node.js项目在导入json文件时需要在typescript编译器选项中声明ResolveJsonModule为true?
标题是描述 我想知道原因。为什么使用typescript的node.js项目在导入json文件时需要在typescript编译器选项中声明ResolveJsonModule为true?,node.js,json,typescript,Node.js,Json,Typescript,标题是描述 我想知道原因。 请让我知道这件事。谢谢。建议性回答 我从中找到了答案 我们在第2行得到一个类型错误。TypeScript不允许我们导入JSON 模块开箱即用,就像那样。这是一个有意识的设计 TypeScript团队做出的决定:拉入大型JSON文件 可能会消耗大量内存,这就是为什么我们需要选择 通过启用--resolveJsonModule编译器,将其转换为该特性 // We no longer need the "use strict" directive since // all
请让我知道这件事。谢谢。建议性回答 我从中找到了答案 我们在第2行得到一个类型错误。TypeScript不允许我们导入JSON 模块开箱即用,就像那样。这是一个有意识的设计 TypeScript团队做出的决定:拉入大型JSON文件 可能会消耗大量内存,这就是为什么我们需要选择 通过启用--resolveJsonModule编译器,将其转换为该特性
// We no longer need the "use strict" directive since
// all ECMAScript modules implicitly use strict mode.
import * as express from "express";
import * as config from "./config.json";
const app = express();
app.listen(config.server.nodePort, () => {
console.log(`Listening on port ${config.server.nodePort} ...`);
});