Import JSON files

tags:  typescript

Problem

TypeScriptTypeScript
Override

Introduced in TypeScript v4.3.

References

https://dev.to/lioness100/introducing-typescript-override-keyword-4b36
https://www.typescriptlang.org/docs/handbook/release-notes/typescrip...
doesn't support by default resolving JSON modules because it needs to infer the static type of the JSON file. In NodeJS Private or Broken Links
The page you're looking for is either not available or private!
projects, it's common practice to import static JSON files so this could bring us to a situation of linting errors.

An example of the error shown:

Cannot find module './settings.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.

In the documentation there isn't a clear example of how to solve this issue.

Solution

Update the tsconfig.json with the parameter resolveJsonModule set to true.

// tsconfig.json
{
  "compilerOptions": {
    // ...
    "resolveJsonModule": true,
    // ...
  },
  "include": [
    // ...
  ]
}

References