adding typings to a imported json file

Viewed 38
import { CharacterDataStructure } from "../../Typings/Interfaces"

declare module "../../Data/Characters/Raw_Characters.json" {
    export = CharacterDataStructure
}

import RawCharacters from "../../Data/Characters/Raw_Characters.json"

enter image description here As you can see, I want to add a type to my JSON file but it recognises it as a non module. The reason why I want to do this is because of my interface,

Here is an example of my data in my json file and my interface: JSON file:

{ id: "character_1", type: "item" }

my interface:

interface CharacterDataStructure {
 id: `character_${number}`
 type: "item"|"power up"
}

When I import my JSON file, it recognises id and type as string(s) and does not check their value to see if they match the interface. And thus this will give me an error

0 Answers
Related