Skip to content

Union discriminated on an "undefined" value throws TypeError for non-object input #1724

Closed

Description

@trackoor

Report a bug

🔎 Search Terms

discriminated union undefined, Cannot use 'in' operator, TypeError primitive

🧩 Context

  • ArkType version: 2.2.9 (@ark/schema 0.56.8; main at 326cdce has no ark/schema changes since)
  • TypeScript version (5.1+): not involved (runtime behavior, plain JS)
  • Other context you think may be relevant (JS flavor, OS, etc.): Node.js 26.13.0, Linux

🧑‍💻 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%2520k%253A%2520%25221%2522%252C%2520a%253A%2520%25222%2522%2520%257D%29.or%28%257B%2520k%253A%2520%25223%2522%252C%2520a%253A%2520%2522undefined%2522%2520%257D%29%250A%250Aconst%2520out%2520%253D%2520Thing%280%29%250A

import { type } from "arktype"

const Thing = type({ k: "1", a: "2" }).or({ k: "3", a: "undefined" })

Thing.allows(0) // TypeError: Cannot use 'in' operator to search for 'k' in 0
Thing(0)        // TypeError: Cannot use 'in' operator to search for 'k' in 0

Expected false and an ArkErrors instance, as with a: "null" in the second branch. The same happens for "s", null and undefined as input.

The union is discriminated on a with an undefined case. pruneDiscriminant then removes the domain: "object" check from that branch, but data?.a === undefined is also true for primitives (and for objects without a: type({ a: "2" }).or({ a: "undefined" }).allows({}) returns true).

Credit: https://ucsbplse.github.io/

Activity

  1. ssalbdivad commented on Nov 18, 2026

    @ssalbdivad
    Member

    Fixed in 3.0.0-beta.0 (#1728). Try it with npm i arktype@next.

  2. moved this from To do to Done (merged or closed) in arktypeioon Nov 18, 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

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done (merged or closed)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions