Skip to content

Prevent primitive types from being type aliased (when using allOf) #504

Description

@Kruptein

I tried moving some things to an allOf setup, which works kinda 1,
but the primitive types are suddenly getting aliased.

e.g.

export type ShapeLocationMoveTarget = PositionTuple & {
  location: Location;
  floor: Floor;
};
export type Location = number;
export type Floor = string;

export interface PositionTuple {
  x: number;
  y: number;
}

For a small setup like this, it's not the worst thing in the world,
but for my real types it's generating hundreds of "useless" types that just bloat the output file.

The above ts output is part of this schema:

{
  "title": "_Master_",
  "type": "object",
  "properties": {
    "PositionTuple": {
      "$ref": "#/definitions/PositionTuple"
    },
    "ShapeLocationMoveTarget": {
      "$ref": "#/definitions/ShapeLocationMoveTarget"
    }
  },
  "required": [
    "PositionTuple",
    "ShapeLocationMoveTarget"
  ],
  "additionalProperties": false,
  "definitions": {
    "PositionTuple": {
      "title": "PositionTuple",
      "type": "object",
      "properties": {
        "x": {
          "type": "integer"
        },
        "y": {
          "type": "integer"
        }
      },
      "required": [
        "x",
        "y"
      ],
      "additionalProperties": false
    },
    "ShapeLocationMoveTarget": {
      "title": "ShapeLocationMoveTarget",
      "allOf": [
        {
          "$ref": "#/definitions/PositionTuple"
        },
        {
          "type": "object",
          "properties": {
            "location": {
              "title": "Location",
              "type": "integer"
            },
            "floor": {
              "title": "Floor",
              "type": "string"
            }
          },
          "required": [
            "location",
            "floor"
          ],
          "additionalProperties": false
        }
      ]
    }
  }
}

Footnotes

  1. It's using type and & instead of interface and extends but I can live with that

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions