Skip to content

Incorrect Type when using type.declare<>()Β #1578

@eralmansouri

Description

@eralmansouri

Using type.declare<Expected>().type({...}) returns a validator that results in an incorrect type when used.

Let's say we defined these two identical validators.

type Expected = { a: number; b?: number }
const Type_with_declare = type.declare<Expected, { side: "out" }>().type({
    a: "string.numeric.parse",
    "b?": "number"
})

const Type_without_declare = type({
    a: "string.numeric.parse",
    "b?": "number"
});

When used, they return different types. Despite the fact that their actual returned values being identical. Essentially, their runtime behavior is still as expected but it's returned Type does not correctly represent it.

// typed as '((In: {a: string; b?: number;}) => Expected) | ArkErrors'
const result_with_declare = Type_with_declare({
    a: "3"
});

// typed as '{a: number; b?: number;} | ArkErrors'
const result_without_declare = Type_without_declare({
    a: "3"
});

In both cases, the actual result is { a: 3 } as expected.

🧩 Context

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

πŸ§‘β€πŸ’» Repro

Playground Link: Here

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