New —resolveJsonModule
Often in Node.js applications a .json
is needed. With TypeScript 2.9, —resolveJsonModule
allows for importing, extracting types from and generating .json
files.
Example
// settings.json
{
"repo": "TypeScript",
"dry": false,
"debug": false
}
// a.ts
import settings from "./settings.json";
settings.debug === true; // OK
settings.dry === 2; // Error: Operator '===' cannot be applied boolean and number
// tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"resolveJsonModule": true,
"esModuleInterop": true
}
}