TypeScript 2.9: Importing JSON Modules

added by JavaScript Kicks
4/22/2019 7:28:37 AM

405 Views

TypeScript 2.9 introduced a new --resolveJsonModule compiler option that lets us import JSON modules from within TypeScript modules. Let's assume we have a Node application written in TypeScript, and let's say that we want to import the following JSON file: { "server": { "nodePort": 8080 } } In Node, we can use a require call to import this JSON file like any other CommonJS module: const config = require("./config.json"); The JSON is automatically deserialized into a plain JavaScript object.


0 comments