Skip to content

toJsonSchema({ useRefs: true }) fails for partially overlapping discriminated union #1511

@eyalkutz

Description

@eyalkutz

Report a bug

🔎 Search Terms

toJsonSchema

🧩 Context

  • ArkType version: 2.1.22
  • TypeScript version (5.1+): bun version 1.2.8, also reproduced in node v22.15.1 without typescript
  • Other context you think may be relevant (JS flavor, OS, etc.):

🧑‍💻 Repro

Playground Link: https://arktype.io/playground?code=import%2520%257Btype%257D%2520from%2520%27arktype%27%253B%250A%250Atype%250A%2520%2520.or%28%250A%2520%2520%2520%2520%257B%250A%2520%2520%2520%2520%2520%2520a%253A%2520type.enumerated%28%2522a%2522%252C%2520%2522b%2522%252C%2520%2522c%2522%29%252C%250A%2520%2520%2520%2520%2520%2520b%253A%2520%271%27%252C%250A%2520%2520%2520%2520%257D%252C%250A%2520%2520%2520%2520%257B%250A%2520%2520%2520%2520%2520%2520a%253A%2520type.enumerated%28%2522a%2522%252C%2520%2522e%2522%252C%2520%2522f%2522%29%252C%250A%2520%2520%2520%2520%2520%2520b%253A%2520%272%27%252C%250A%2520%2520%2520%2520%257D%250A%2520%2520%29%250A%2520%2520.toJsonSchema%28%257B%2520useRefs%253A%2520true%2520%257D%29%253B

import {type} from 'arktype';

type
  .or(
    {
      a: type.enumerated("a", "b", "c"),
      b: '1',
    },
    {
      a: type.enumerated("a", "e", "f"),
      b: '2',
    }
  )
  .toJsonSchema({ useRefs: true });

note that this code does run without errors if { useRefs: false }

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

To do

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions