Skip to content

Self-referential union: union base + self-mapping + direct allOf child renders its own union inside itself (TS2456) #95

Open

Description

@TheAsda

Discovered during review of #94 (pre-existing on e3d0555 — not a regression from the concrete-base fix; the old build fails the same shape with 3 errors instead of 2).

Problem

When a discriminator base is a union (oneOf/anyOf) and lists itself in its own mapping and has a direct allOf child, the base's own definition renders its union inline — which contains the base itself:

components:
  schemas:
    Circle:
      oneOf:
        - $ref: '#/components/schemas/Circle'
        - $ref: '#/components/schemas/Square'
      discriminator:
        propertyName: shape
        mapping:
          Circle: '#/components/schemas/Circle'
          Square: '#/components/schemas/Square'
    Square:
      allOf:
        - $ref: '#/components/schemas/Circle'
        - type: object
          properties:
            radius: { type: number }

Generated output (simplified):

export type Circle = (Circle | Square) & /* … */;  // TS2456: 'Circle' implicitly has type 'any' — self-reference in its own initializer

Root cause sketch

In the same-family spine path, a self-mapped union base is registered as a member with isUnion: true; mapSameFamilySpineRef's inline fallback expands the union inline at the base's own definition site, producing a circular type alias (src/analyzer/schema-mapper.ts, inline fallback).

Possible directions

  • Emit the base's union-arm members by name at its own definition instead of inlining (named union members are declared independently).
  • Or detect the cycle and fall back to the bare union name / warn.

Notes

Activity

  1. added
    needs-triageNew issue awaiting triage (agent-ready issues move to ready-for-agent)
    on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageNew issue awaiting triage (agent-ready issues move to ready-for-agent)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions