-
Notifications
You must be signed in to change notification settings - Fork 392
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
Use of allOf
makes some properties disappear
#152
Comments
Hi @vsund! This is probably a symptom of #96. What happens when you update your schema like this: {
"$schema": "http://json-schema.org/schema#",
"allOf": [
{
"$ref": "src/profiles/schemas/Profile.json"
},
{
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"required": [
"name"
]
}
]
} |
Wow, that was quick ;) Saw that issue, but somehow I wasn't able to connect it to my problem. Your suggestion gives me a export type Person = {
'@context': string;
'@type': string;
'@id': string;
[k: string]: any;
} & {
name: string;
[k: string]: any;
}; which works like a charm. Will go with this until #96 is resolved. I guess now it makes sense why it's a type literal. I believe you cannot link two interfaces? |
It’s mostly a stylistic choice, because sometimes unnamed schemas are declared inline and sometimes we pull them out. If you want an interface, define an “id” property on Person’s schema. |
see bcherny/json-schema-to-typescript#152 Change-Id: Iebe2d00452f09400c8250e412cefd9bfb555513c
First of all, big thanks for this library!
I'm not sure whether I misunderstood what I do or this tool produces wrong output. But somehow it's not doing what I expected :D
I have the two schemas from below.
Person.json
should take all rules fromPerson.json
and add aname
property.If I throw them into
json2ts
I get the following outputWhile this is in theory correct (
[k: string]: any
includes everythingPerson.json
specifies), it's hard to specify properties inPerson.json
. I expected it to include thename
property explicitly:Also wondering why the output from
Person.json
is a type literal while the one fromProfile.json
is an interface 🤔Anyway, thanks for all help in advance.
Profile.json
Person.json
Profile.json.d.ts
The text was updated successfully, but these errors were encountered: