Skip to content

type.map() collapses discriminated union #1524

Closed

Description

@DrJume

Report a bug

When mapping a discriminated union with .map() it causes the union to collapse into one merged type, losing it's discrimination.
I am not sure if this is a bug or a limitation of TypeScript runtime inference.

🔎 Search Terms

  • map
  • union
  • discriminated

🧩 Context

  • ArkType version: 2.1.23
  • TypeScript version (5.1+): 5.9.3

🧑‍💻 Repro

Playground Link: https://arktype.io/playground?code=import%2520%257B%2520type%2520%257D%2520from%2520%2522arktype%2522%250A%250Aconst%2520T%2520%253D%2520type%250A%252F%252F%2520%2520%2520%2520%255E%253F%250A%2509.or%28%250A%2509%2509%257B%2520name%253A%2520%2522%27number%27%2522%252C%2520type%253A%2520%2522number%2522%2520%257D%252C%250A%2509%2509%257B%2520name%253A%2520%2522%27string%27%2522%252C%2520type%253A%2520%2522string%2522%2520%257D%250A%2509%29%250A%2509.map%28%28t%29%2520%253D%253E%2520%257B%250A%2509%2509if%2520%28t.key%2520%253D%253D%253D%2520%2522type%2522%29%250A%2509%2509%2509return%2520%257B%250A%2509%2509%2509%2509...t%252C%250A%2509%2509%2509%2509value%253A%2520t.value.array%28%29%250A%2509%2509%2509%257D%250A%250A%2509%2509return%2520t%250A%2509%257D%29%250A

import { type } from "arktype"

const T = type
//    ^?
	.or(
		{ name: "'number'", type: "number" },
		{ name: "'string'", type: "string" }
	)
	.map((t) => {
		if (t.key === "type")
			return {
				...t,
				value: t.value.array()
			}

		return t
	})

typeof T

const T: Type<{
    name: "string" | "number";
    type: string[] | number[];
}, {}>

Expected

const T: Type<{
    name: "string";
    type: string[];
} | {
    name: "number";
    type: number[];
}, {}>

Activity

  1. added
    bug
    on Oct 22, 2025
  2. ssalbdivad commented on Nov 18, 2026

    @ssalbdivad
    Member

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

  3. 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

Labels

bug

Type

No type

Projects

  • Status
    Done (merged or closed)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions