Skip to content

0.44.0 intersection types regression #387

Open
@laat

Description

@laat

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#'
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions