-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Declare a type with a JSON file instead of an interface #23898
Comments
You are in luck! #22167 just got merged, and with with type schemaType = typeof import("./schema.json"); |
nice that is cool, how do we know when the next |
It is published nightly around midnight PST |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
@mhegazy one potential improvement! tsc can now use .json files for types - but can 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 ? |
@mhegazy what about importing json files and getting type info? If I do: import json = require('../../my.json') and also use:
in my tsconfig.json. My project no longer compiles correctly. Is this a known problem? Should I file a new ticket? |
yes please. |
Search Terms
typescript json interface file
Suggestion
I have this question on SO:
https://stackoverflow.com/questions/50181254/static-typing-with-json-and-typescript?noredirect=1#comment87380729_50181254
Why can't we declare a TS type based on a .json file? Something like this:
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)
The text was updated successfully, but these errors were encountered: