ts-json icon indicating copy to clipboard operation
ts-json copied to clipboard

Errors

Open daslicht opened this issue 7 years ago • 3 comments

Hi, when I try the following :

import * as config from '../config/config.json';

I get: [ts] Cannot find module '../config/config.json'.

any idea ?

daslicht avatar Apr 12 '17 16:04 daslicht

+1 same here

surfjedi avatar May 03 '17 16:05 surfjedi

@daslicht and @surfjedi This solution is not working any more, unfortunately.

What you need to do is keep the declaration the same in your typings.d.ts (personally, I always create a separate json.d.ts file for this):

declare module '*.json' {
  const value: any;
  export default value;
}

And import your JSON data with:

import config from '../config/config.json'; // not * as config

nfantone avatar May 28 '17 18:05 nfantone

Ok, after playing around with this repo for a while I came back just to say that I couldn't make my approach work, sadly.

The way this project is set up seems to make the import statement work just fine. Oddly enough, it didn't in any of my Angular code bases. Conversely, I failed to apply what I was doing in my personal projects here.

🤷‍♂️

Also, since we are using export default, it'd make sense for the imported symbol to be able to compile and be interpreted as:

import data from './example.json';

rather than

import * as data from './example.json';

nfantone avatar May 28 '17 18:05 nfantone