-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
Bug Report
π Search Terms
variadic tuple bug
π Version & Regression Information
The same behavior is visible from 4.2.3 through 4.8dev
although it it as only been a bug since variadic tuples.
β― Playground Link
Playground link with relevant code
π» Code
// These should be OK since variadic tuples (rest can go anywhere)
// versions 4.2.3 ~ 4.8 dev.
{
type T12 = ["^", ...(string | boolean | undefined)[], "$"]
const t12a:T12 = ["^", "$"]; // Should not be an error
const t12b:T12 = ["^", true, "$"]; // Should not be an error
}
π Actual behavior
As shown.
π Expected behavior
Not errors, because a match exists.
Additional Info
I examined the code. checkArrayLiteral
in checker.ts
performs a unidirection (left to right) search only,
However, the output from createNormalizedTupleType
outputs a normalized type that can have a single tuple in the middle (like the one in the example).
That requires a bidirectional search to get the right results.
Alternatively, createNormalizedTupleType
could be forced to roll up everything after the first rest into a single rest. But such an algorithm would result in more false postives (false passes) than necessary. So a bidirectional search is preferable.
I can provide more details if necessary. (I even have bi-directional search code that passes all the baselines tests). Just ask if you want it.