Skip to content

type.declare: tuple optional/variadic elements, assignable object unions, and side: "in" defaulted keys #1776

Done

Description

@ssalbdivad

Three remaining false rejections in ark/type/declare.ts (related to #1483):

Repros

// 1. Optional and variadic tuple elements (S11)
type.declare<[string, number?]>().type(["string", "number?"])             // declared: number | undefined, inferred: number
type.declare<[string, ...number[]]>().type(["string", "...", "number[]"]) // rejected

// 2. Object union member with assignable: true (S12)
type U = { kind: "a"; a: string } | { kind: "b"; b: number }
type.declare<U, { assignable: true }>().type({ kind: "'a'", a: "string" })
// TS2353: 'a' does not exist in type '{ kind: unknown }'

// 3. Default on a declared-optional key with side: "in" (S13)
type.declare<{ a?: number }, { side: "in" }>().type({ a: "number = 1" })
// "did you mean 'a?'" ("a?" cannot hold a default)

Causes & Fixes

  • S11 (ark/type/declare.ts:79-92 validateArrayInference): Maps declared tuple index-by-index against declared[i] (which includes undefined for optional slots) and misaligns "..." rest elements. Compare optional elements against Required<declared>[i] and fall back to equals<inferDefinition<def>, declared> when "..." is present.
  • S12 (ark/type/declare.ts:101-135 validateObjectKeys): Extracts requiredKeyOf<declared> over the union as a whole so non-shared keys vanish. Distribute declaredObjectOf over union members when assignable: true.
  • S13 (ark/type/declare.ts:230 declaredOptionalKeySuggestion): Only permits OptionalPropertyDefinition; allow defaultable definitions (${string} = ${string} / [def, "=", v]) when side is "in".

Activity

  1. ssalbdivad commented on Dec 3, 2026

    @ssalbdivad
    MemberAuthor

    all three type.declare items (tuple optional/variadic, assignable unions, side: "in") were fixed in 3.0.0 (2c65fce4c, fdcb8704c) — closing.

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