Skip to content

toJsonSchema() fails when a field is string | undefined #1462

Open

Description

@VanTanev

Report a bug

When trying to convert a type like:

const Thing = type({
    maybe: "string | undefined",
})

I get the following exception:

ToJsonSchemaError: {
    code: "unit",
    base: {},
    unit: undefined
}

🔎 Search Terms

jsonschema

🧩 Context

  • ArkType version: 2.1.20
  • TypeScript version (5.1+): 5.8

🧑‍💻 Repro

Playground Link: https://arktype.io/playground?code=import%2520%257B%2520type%2520%257D%2520from%2520%2522arktype%2522%250A%250Aconst%2520Thing%2520%253D%2520type%28%257B%250A%2520%2520%2520%2520maybe%253A%2520%2522string%2520%257C%2520undefined%2522%252C%250A%257D%29%250A%250Aconst%2520out%2520%253D%2520Thing%28%257B%250A%2520%2520%2520%2520maybe%253A%2520undefined%252C%250A%257D%29%250A

Activity

  1. added
    bug
    on Jun 4, 2025
  2. fasetto commented on Apr 12, 2026

    @fasetto

    type.enumerated(["first", "sec"]) also fails.

    ToJsonSchemaError: {
        code: "unit",
        base: {},
        unit: [
            "first",
            "sec"
        ]
    }
    

    playground

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions