-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Is it possible to link typescript interfaces to JSON files? #9225
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
Comments
Hey @sandy081, can you elaborate on the specific request here? |
@Sequoia is the original author of this issue.. Can you please help/reply to the above comment. Thanks. |
(Sorry, I might've just hit |
Current behavior
Requested
export interface Bar {
/** Version is the version number */
version: number;
description?: string;
} Currently you can link an interface to an object in JS via
And get type hinting. I'm wondering if you can link an interface to an object serialized in a json file & get that same hinting. |
I still can't tell what you're describing. |
Actually I was looking for something similar. I will try to elaborate the idea using a practical example. JSON data {
"logLevel": "LOG"
} JSON schema {
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {},
"id": "http://example.com/example.json",
"properties": {
"logLevel": {
"default": "OFF",
"enum": [
"OFF",
"LOG",
"DEBUG",
"INFO",
"WARN",
"ERROR"
],
"id": "/properties/logLevel",
"type": "string"
}
},
"required": [
"logLevel"
],
"type": "object"
} TypeScript interface export interface RootObject {
logLevel: 'OFF' | 'LOG' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR'
} Is there a way to sync JSON schema and TypeScript interface? |
I was thinking about something similar -- being able to substitute typescript
|
I have manually taken schemas and output them to interfaces using json-schema-to-typescript though there are both examples of how to use it in browser as well as a server, which of course you could then do on the fly. |
For our scenario, JSON-Schema is rapidly becoming a complete failure. The Azure Resource Schemas have well over a hundred types (and if I actually include everything, hundreds )... which grinds VS's json editor into the ground. (see https://github.com/azure/azure-resource-manager-schemas/blob/master/schemas/2015-01-01/deploymentTemplate.json#L40 ) Worse, because of the way that schema validation and 'intellisense' works, it gets pretty damn confused as what permissible values are in some cases. And, to top that all off, upcoming work could explode that by an order of magnitude. Which is why I'm looking at seeing if I can accomplish a similar feat using |
@RyanCavanaugh I want to write a tsd and link to it via $schema from a json file like I would link to a json schema. To think of it another way, I want to use tsd in a json file just as I can using |
If I get it correctly, this proposal would mean extending TypeScript to support This would be a really cool feature and I, personally, would love to use it. But it also seems to be quite complicated to implement and it probably wouldn't be worth it, unless there is a great demand from the community… |
For historical purposes: This was never a typescript issue and should not have been migrated here. Apologies for not noticing this sooner–it lead to the confusion around what I was asking for. This was a VSCode feature request, the ability to add type hinting in JSON files by linking them via $schema to typescript definitions.
The behavior is almost the same, just |
From @Sequoia on June 16, 2016 20:3
I know it's possible to do this with json schemas but is it possible to do this with a typescript interface?
Copied from original issue: microsoft/vscode#7792
The text was updated successfully, but these errors were encountered: