I need to validate JSON with typescript. I wanted to do this like so:
jsonFile.json
{
"foo": "bar",
"fiz": "baz",
"potato": 4
}
JSONType.ts
type JSONType = typeof jsonFile;
jsonFile2.json
{
"foo": 5,
"fiz": false
};
and if I do this:
const jsonFile2: JSONType = JSONFile2
I want it to throw an errors for not matching types, and a missing property.
I essentially want to make sure two JSONs have the same structure, with one of them as the source of truth. How do I do that?