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
Declare a type with a JSON file instead of an interface #23898
it seems like a no-brainer to me, but maybe I am stupid.
Use Cases
Keep things DRY. Use JSON files as interfaces.
Examples
Done did.
Checklist
My suggestion meets these guidelines:
[x] This wouldn't be a breaking change in existing TypeScript / JavaScript code
[x] This wouldn't change the runtime behavior of existing JavaScript code
[x] This could be implemented without emitting different JS based on the types of the expressions
[x] This isn't a runtime feature (e.g. new expression-level syntax)
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
mhegazy commentedon May 4, 2018
You are in luck! #22167 just got merged, and with
--resolveJsonModuleyou can load the json object in your program and use its type..with
importtypes too you can capture that type in a type alias:ORESoftware commentedon May 5, 2018
nice that is cool, how do we know when the next
tscversion will be published on NPM? is there some notification system?mhegazy commentedon May 5, 2018
It is published nightly around midnight PST
typescript-bot commentedon May 21, 2018
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
ORESoftware commentedon Jun 16, 2018
Mohamed Hegazy (@mhegazy) one potential improvement!
tsc can now use .json files for types - but can
tscuse json-schema files to determine generic types?for example, say I have this JSON file:
{ "foo":"bar" }now, foo the interface for the above could be:
or it could be:
which does
tsccurrently do? Couldtscbe updated to handle json-schema fromhttp://json-schema.org/
?
ORESoftware commentedon Jun 25, 2018
Mohamed Hegazy (@mhegazy) what about importing json files and getting type info? If I do:
and also use:
"resolveJsonModule": true,in my tsconfig.json. My project no longer compiles correctly. Is this a known problem? Should I file a new ticket?
mhegazy commentedon Jun 25, 2018
yes please.
ORESoftware commentedon Jun 26, 2018
Mohamed Hegazy (@mhegazy) thanks, I filed the issue here: #25216