-
Notifications
You must be signed in to change notification settings - Fork 216
Closed
Labels
Description
export interface A {a: string;}
export interface B extends A {b?: string;}
generates
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"B": {
"allOf": [
{
"type": "object",
"properties": {
"b": {
"type": "string"
}
},
"required": [],
"additionalProperties": false
},
{
"$ref": "#/definitions/A"
}
]
},
"A": {
"type": "object",
"properties": {
"a": {
"type": "string"
}
},
"required": [
"a"
],
"additionalProperties": false
}
},
"$ref": "#/definitions/B"
}
The following object type checks correctly with TypeScript. However, it does not validate against the JSON schema. This is because B
uses an allOf
where each branch has additionalProperties: false
(i.e., it fails the first branch).
const foobar:B = {a: 'foo'};
I believe ts2json should be consolidating these definitions together. Note: Switching allOf
to anyOf
doesn't yield a correct schema either ({b: 'foo'}
correctly validates for instance).