TSConfig
resolveJsonModule
Allows importing modules with a .json
extension, which is a common practice in node projects. This includes
generating a type for the import
based on the static JSON shape.
TypeScript does not support resolving JSON files by default:
tsTry
// @filename: settings.json{"repo": "TypeScript","dry": false,"debug": false}// @filename: index.tsimportCannot find module './settings.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.2732Cannot find module './settings.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.settings from"./settings.json" ;settings .debug === true;settings .dry === 2;
Enabling the option allows importing JSON, and validating the types in that JSON file.
tsTry
// @filename: settings.json{"repo": "TypeScript","dry": false,"debug": false}// @filename: index.tsimportsettings from "./settings.json";settings .debug === true;This comparison appears to be unintentional because the types 'boolean' and 'number' have no overlap.2367This comparison appears to be unintentional because the types 'boolean' and 'number' have no overlap.settings .dry === 2;