I have a json file of translations that I want to use in my angular 4 project. The file is also used in php which is why it needs to be stored as json rather than as a js module.
It has this structure
export interface IDictionary {
amsterdamCenter: number[];
amsterdamBounds: Array<number[]>;
prices: Price[];
cuisines: Object;
areas: Object;
}
Following https://hackernoon.com/import-json-into-typescript-8d465beded79 I have changed typings.d.ts to read
/* SystemJS module definition */
declare var module: NodeModule;
interface NodeModule {
id: string;
}
declare module "*.json" {
const value: any;
export default value;
}
Now I have an error with
import * as dictionary from './dictionary.json';
export const Dictionary: IDictionary = dictionary;
[ts] Type 'typeof ".json"' is not assignable to type 'IDictionary'. Property 'amsterdamCenter' is missing in type 'typeof ".json"'.
However
export const Dictionary: any = dictionary;
does work. I'm hoping there is an incantation of TS that will permit me to import typescript using my interfaces
any, so:export const Dictionary: IDictionary = dictionary as any;import dictionary from './dictionary.json';and no additional casting will be needed (as it is already defined asany)