You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow checking json in conjunction with .d.json.ts filesΒ #52994
// main.tsimportconfigfrom"./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.
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.
This potentially opens a larger can of worms - should .js files be type-checked in accordance with their corresponding .d.ts as well? Currently this doesnβt happen, by design, though several people have asked for it (and been declined).
This potentially opens a larger can of worms - should .js files be type-checked in accordance with their corresponding .d.ts as well? Currently this doesnβt happen, by design, though several people have asked for it (and been declined).
With JS people can already use jsdoc, with JSON there is simply nowhere we could put TS types (perhaps in JSONC, but browsers/node/deno/etc don't support importing that), I did propose using JSON Schema but there seemed to be no interest due to how different it is from TS types.
Activity
fatcerberus commentedon Feb 27, 2023
This potentially opens a larger can of worms - should
.jsfiles be type-checked in accordance with their corresponding.d.tsas well? Currently this doesnβt happen, by design, though several people have asked for it (and been declined).Jamesernator commentedon Feb 28, 2023
With JS people can already use jsdoc, with JSON there is simply nowhere we could put TS types (perhaps in JSONC, but browsers/node/deno/etc don't support importing that), I did propose using JSON Schema but there seemed to be no interest due to how different it is from TS types.
fix: TS LSP being slow (#7181)