Skip to content

type.declare composition with undefined #1537

Closed

Description

@nnstanusic

Report a bug

I've been playing with arktype and trying to compose validators using preexisting types with type.declare .
When adding undefined this falls apart during compilation.

🔎 Search Terms

I didn't I asked a question on the discord server and it turned out to be a bug.
@ssalbdivad prompted me to create an Issue

🧩 Context

  • ArkType version: 2.1.25
  • 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%250A%250Atype%2520Member%2520%253D%2520%27a%27%2520%257C%2520%27b%27%2520%257C%2520undefined%253B%2520%252F%252F%2520withough%2520undefined%2520it%2520works%250Aconst%2520memberValidator%2520%253D%2520type.declare%253CMember%253E%28%29.type%28%2560%2522a%2522%2520%257C%2520%2522b%2522%2520%257C%2520undefined%2560%29%253B%250A%250Atype%2520Object%2520%253D%2520%257B%250A%2520%2520m%253A%2520Member%253B%250A%257D%253B%250Aconst%2520Thing%2520%253D%2520type.declare%253CObject%253E%28%29.type%28%257B%250A%2520%2520m%253A%2520memberValidator%252C%250A%257D%29%253B%250A%250Aconst%2520out%2520%253D%2520Thing%28%257B%2520m%253A%2520%27a%27%2520%257D%29%253B

import { type } from 'arktype';

type Member = 'a' | 'b' | undefined; // withough undefined it works
const memberValidator = type.declare<Member>().type(`"a" | "b" | undefined`);

type Object = {
  m: Member;
};
const objectValidator = type.declare<Object>().type({
  m: memberValidator,
});

const output = objectValidator({ m: 'a' });

Note

In the repro link the compilation issue is not visible, the behaviour can be observed here:
https://stackblitz.com/edit/vitejs-vite-cpr8tkpa?file=src%2Fmain.ts

Activity

  1. moved this from To do to Planned in arktypeioon Nov 18, 2025
  2. moved this from Planned to In progress in arktypeioon Nov 24, 2025
  3. moved this from In progress to Implemented in arktypeioon Nov 24, 2025
  4. ssalbdivad commented on Dec 3, 2025

    @ssalbdivad
    Member

    fixed in 2.1.28

    #1558

  5. moved this from Implemented to Done (merged or closed) in arktypeioon Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

  • Status
    Done (merged or closed)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions