Here is a snippet of the JSON file (test.json) I am working with:
{"test":[
{"file": "f1.txt", "nr":3},
{"file": "f4.txt", "nr":4},
{"file": "f7.txt", "nr":7}
]}
In TypeScript, I've created an interface to represent this JSON structure:
export interface IJsonFiles {
test: (FileEntity)[];
}
interface FileEntity{
file: string;
nr: number;
}
To properly import the JSON in my TypeScript code, I had to include a json.d.ts file like so:
declare module "*.json" {
const value: any;
export default value;
}
Now, when trying to import test.json into my code using the following statement:
import * as b from '../../assets/test.json';
let files: IJsonFiles;
files = b;
I encounter the following error message:
TS2322: Type 'typeof import("*.json")' is not assignable to type 'IJsonFiles'. Property 'test' is missing in type 'typeof import("*.json")'.
If anyone can provide assistance, it would be greatly appreciated. The end goal is to import JSON files without using require and to have the JSON structure defined properly in TypeScript.