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

ts2556 is too restrictive when generics are involved #57322

Open
mkantor opened this issue Feb 7, 2024 · 2 comments
Open

ts2556 is too restrictive when generics are involved #57322

mkantor opened this issue Feb 7, 2024 · 2 comments
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@mkantor
Copy link
Contributor

mkantor commented Feb 7, 2024

🔎 Search Terms

"generic", "tuple", "spread", "rest", "ts2556", "a spread argument must either have a tuple type or be passed to a rest parameter"

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about spreading into argument lists

⏯ Playground Link

https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEYD2A7AzgF3gMwFzwAoBKeAXgD54A3JAS2AFgAoZ0SWBZdLAD3zijBUEAJ7wA2gF1m2AgDoFPEgHpl8AO5IYAazTNmXTPAwgjpeAB4AKvBA8TKYGngChKURMnkCfeFZIUzPA48ooqakKm8ChIWJo6QA

💻 Code

declare const f: () => void

declare const x: readonly []
f(...x) // works

const test = <T extends readonly []>(x: T) =>
  f(...x) // does not work

🙁 Actual behavior

Attempting to spread a generically-typed value whose constraint guarantees tuple-ness into a compatible argument list is forbidden.

🙂 Expected behavior

I should be allowed to do this.

Additional information about the issue

Possibly-related issues:

@Andarist
Copy link
Contributor

Andarist commented Feb 7, 2024

It's likely that this one would get fixed by #53615

@KaffinPX
Copy link

KaffinPX commented Feb 7, 2024

Thanks a lot @mkantor ;)

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels Feb 7, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
Development

No branches or pull requests

4 participants