0.44.0 intersection types regression
types.ts given these types:
export interface Links {
readonly self: HrefLink;
readonly myLink: HrefLink & TemplatedLink;
}
export interface HrefLink {
readonly href: string;
}
export interface TemplatedLink {
readonly templated: true;
}
program.ts and a program that generates the schema:
import path from 'path';
import util from 'util'
import * as TJS from 'typescript-json-schema';
const program = TJS.getProgramFromFiles([path.join(__dirname, "types.ts")]);
const schema = TJS.generateSchema(program, "Links", {
noExtraProps: true, // important
});
console.log(util.inspect(schema, { depth: Infinity }));
0.43.0 gives the expected intersection:
{
type: 'object',
properties: {
self: { '$ref': '#/definitions/HrefLink' },
myLink: {
additionalProperties: false,
type: 'object',
properties: {
href: { type: 'string' },
templated: { type: 'boolean', enum: [ true ] }
}
}
},
additionalProperties: false,
definitions: {
HrefLink: {
type: 'object',
properties: { href: { type: 'string' } },
additionalProperties: false
}
},
'$schema': 'http://json-schema.org/draft-07/schema#'
}
0.44.0 HrefLink properties is missing in myLink:
{
type: 'object',
properties: {
self: { '$ref': '#/definitions/HrefLink' },
myLink: {
additionalProperties: false,
type: 'object',
properties: { templated: { type: 'boolean', enum: [ true ] } }
}
},
additionalProperties: false,
definitions: {
HrefLink: {
type: 'object',
properties: { href: { type: 'string' } },
additionalProperties: false
}
},
'$schema': 'http://json-schema.org/draft-07/schema#'
}
Could that be coming from https://github.com/YousefED/typescript-json-schema/pull/383? cc @darkowic
Not sure... But we do have a similar test here https://github.com/YousefED/typescript-json-schema/blob/master/test/programs/type-intersection/main.ts and everything is passing on CI.
I bisected the commits, and it was introduced in b69cd3cf87107f4cac71af6dc50d85780506f8ac
Can you improve the test scenarios and try to handle it? I did in this comment my best but if something was not covered then it is hard to be safe... Maybe I will have time at the weekend to look at it...
It's very understandable that it happens when it's not covered by tests, this just happens from time to time. Nobody blames you :)
I can create a PR with a test-case that should pass, but I'm afraid that I'm not familiar enough with the guts of this package to fix it.
@darkowic I have added a test that fails in #388.
I have verified that this test passed before b69cd3c.
I'm sorry that I cannot be of more help.
Thank you for debugging, providing a test case, and helping to fix the issue both of you!
Hey guys, do you know if there is any progress with this issue?