Skip to content

the union between a tuple of n>1 elements and an array of such tuples does properly parse the array case correctly #1317

Closed

Description

@elee1766

Report a bug

the union between [x,x][] and [x,x] does not properly resolve [x,x][] correctly

[ [ 1, 2 ] ] 
must be a number or an object (was undefined)
value at ["1"] must be a number or an object (was undefined)
ReadonlyPath(1) [ '1', cache: { stringifyAncestors: [ '', '["1"]' ] } ]

i actually noticed this with type(["number", "number", "number", "number"])
but it also happens with type(["number","string"]) and probably other cases

🔎 Search Terms

tuple union
array union
tuple array
tuple and tuple array union

🧩 Context

  • ArkType version: 2.0.4
  • TypeScript version (5.1+): 5.7.3
  • Other context you think may be relevant (JS flavor, OS, etc.):

🧑‍💻 Repro

import {ArkErrors, type} from "arktype";


const tupleType = type(["number","number"])
const tupleArrayType = tupleType.array()
const unionType = tupleType.or(tupleArrayType)

// good
tupleType.assert([1,2])
// good
tupleArrayType.assert([[1,2]])

// no good!
const resp = unionType([[1,2]])
if(resp instanceof ArkErrors) {
  const err = resp[0]
  console.log(err.problem)
  console.log(err.message)
  console.log(err.path)
}

Activity

  1. added
    bug
    on Feb 18, 2025
  2. elee1766 commented on Feb 18, 2025

    @elee1766
    Author

    for my use case, i was able to get around it by just doing

        coords: type("boolean | null")
        .or(type("number[] == 4"))
        .or(type("number[] == 4").array())
    

    avoiding the tuples entirely, but others might not be as lucky

  3. ssalbdivad commented on Feb 23, 2025

    @ssalbdivad
    Member

    Just tested this and it was fixed as a side effect of the other discrimination improvements that were made in 2.1.0 🎉

  4. moved this from To do to Done (merged or closed) in arktypeioon Feb 23, 2025
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