Suggestion
π Search Terms
checkJson, check json, .d.json.ts
β
Viability Checklist
My suggestion meets these guidelines:
β Suggestion
So in TS 5.0 we can add .d.json.ts files to type JSON files, i.e.:
// config.d.json.ts
declare const config: {
option?: string,
option2?: number,
};
export default config;
// main.ts
import config from "./config.json" assert { type: "json" };
// config has type { option?: string, option2?: number }
This is nice, but it would be better if we could validate that the corresponding .json files do in fact actually match the type. I'd like to propose a new option, checkJson that when set validates types errors within JSON files.
For example suppose we have:
// config.d.json.ts
declare const config: {
value: string,
};
export default config;
Then TypeScript would report a type error when running tsc on the project (or in the editor).
π Motivating Example
Pretty much anywhere manual JSON files are used in conjunction with .d.json.ts files would be useful. The point of TS is to help detect errors, extending this to JSON is a natural extension.
In particular this would make a particularly good alternative to JSON schema support as I proposed in another issue.
Suggestion
π Search Terms
checkJson, check json, .d.json.ts
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
So in TS 5.0 we can add
.d.json.tsfiles to type JSON files, i.e.:This is nice, but it would be better if we could validate that the corresponding
.jsonfiles do in fact actually match the type. I'd like to propose a new option,checkJsonthat when set validates types errors within JSON files.For example suppose we have:
Then TypeScript would report a type error when running
tscon the project (or in the editor).π Motivating Example
Pretty much anywhere manual JSON files are used in conjunction with
.d.json.tsfiles would be useful. The point of TS is to help detect errors, extending this to JSON is a natural extension.In particular this would make a particularly good alternative to JSON schema support as I proposed in another issue.