Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variadic tuple assignment fail #49138

Closed
craigphicks opened this issue May 16, 2022 · 4 comments
Closed

Variadic tuple assignment fail #49138

craigphicks opened this issue May 16, 2022 · 4 comments
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@craigphicks
Copy link

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.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels May 19, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone May 19, 2022
@Andarist
Copy link
Contributor

note from my issues scavenger hunt: this issue was extracted from #49105 and the draft PR here seems to implement a fix for this

@craigphicks
Copy link
Author

Seems to have been fixed in 5.0.4

@Andarist
Copy link
Contributor

Andarist commented Dec 28, 2023

This was fixed between 5.0.0-dev.20230218 and 5.0.0-dev.20230219, so likely by #52769

@craigphicks
Copy link
Author

@Andarist - Thank you very much for finding that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants