0

In my vue project, I have a json file that I import into my script (typescript) with import jsonData from '@/assets/data1.json';

I can access its data and it works fine, but during the build I'm getting a ton of warnings like this one:

WARNING in /path/src/assets/data1.json
1:1 unused expression, expected an assignment or function call
  > 1 | {
      | ^
    2 |     "x123": {
    3 |         "name": "John Doe",
    4 |         "confirmed": true

What should I do to tell the compiler that the file is actually a json file and not javascript/typescript?

To get this to work I've already added

    "resolveJsonModule": true,
    "esModuleInterop": true  

to tsconfig.json as described here: https://stackoverflow.com/a/50830840/86845

João Portela
  • 6,338
  • 7
  • 38
  • 51

1 Answers1

1

You can disable this warning by excluding json files on your tslint.json file like this:

"linterOptions": { "exclude": [ "*.json", "**/*.json" ] }

the ** is for it to be recursive

David Porcel
  • 290
  • 1
  • 6
  • You were right. But I've only added the `"**/*.json"` rule. `**/` usually means any directory depth (including zero), so I thought the other entry shouldn't be necessary. – João Portela Nov 19 '19 at 08:51