Sunday 10 January 2021

Use json Data in a typescript project

Let's say that you have some json data that you would like to leverage in your project, could be something like config files. well you can import the module like so

      .then(module => this.fingerRational = (module.default as unknownas IFingerRational[]);

However you will get an error saying something like

Module '@/mockData/fingerRational.json' was resolved to 'd:/dev/eDoc_Panels_Frontend/trunk/src/mockData/fingerRational.json', but '--resolveJsonModule' is not used.ts(7042)

the solution is simple you have to modify your tsconfig.json file

  "compilerOptions": {
    "resolveJsonModule"true//<----- added for mock data
    "types": [
    "paths": {
      "@/*": [
    "lib": [
  "include": [
  "exclude": [

and voilia all should be well