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

Manipulated tuple type not allowed to be spread/not recognized as iterable #53089

Closed
majellin24 opened this issue Mar 4, 2023 · 3 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@majellin24
Copy link

majellin24 commented Mar 4, 2023

Bug Report

πŸ”Ž Search Terms

tuple type spread, symbol iterator spread

πŸ•— Version & Regression Information

  • This changed between versions 4.6.4 and 4.7.4

⏯ Playground Link

Playground link

πŸ’» Code

type Mapped<T extends any[]> = { [ P in keyof T ] : T[P] }

function fn<T extends (...args: any[]) => any>(cb: T, ...rest: Mapped<Parameters<T>>): ReturnType<T> {
  return cb(...rest);
  //           ^?
}

πŸ™ Actual behavior

The code failed to compile with the error


Type 'Mapped<Parameters>' must have a 'Symbol.iterator' method that returns an iterator.


πŸ™‚ Expected behavior

Prior to 4.7.4 this compiled. I included the types "paramsOfTest" and "paramsOfNone" to demonstrate that the resulting types do evaluate to tuples, even without any parameters. It seems to me that the type should always evaluate to an iterable tuple since the "Parameters" type should evaluate to a tuple and the types ReplaceIndexWithUndefined and FilterUndefined should also evaluate to iterable types due to their type constraints.

Edited to use the simpler repro from comments to simplify.

Given that this was working previously and I was not able to find more information I assumed this was a bug but I apologize if I have missed something.

@whzx5byb
Copy link

whzx5byb commented Mar 4, 2023

A simpler repo:

type Mapped<T extends any[]> = { [ P in keyof T ] : T[P] }

function fn<T extends (...args: any[]) => any>(cb: T, ...rest: Mapped<Parameters<T>>): ReturnType<T> {
  return cb(...rest); //<- unexpected error here. works in 4.6.4
}

Note that it works when remove the constraint T extends any[] in Mapped<T extends any[]>.

@Andarist
Copy link
Contributor

Andarist commented Mar 4, 2023

Likely a duplicate of #29919

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 7, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants