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

Contextual parameters not inferred from variadic tuples with trailing elements #52846

Closed
Andarist opened this issue Feb 18, 2023 · 0 comments Β· Fixed by #53036
Closed

Contextual parameters not inferred from variadic tuples with trailing elements #52846

Andarist opened this issue Feb 18, 2023 · 0 comments Β· Fixed by #53036
Assignees
Labels
Fix Available A PR has been opened for this issue Suggestion An idea for TypeScript

Comments

@Andarist
Copy link
Contributor

Bug Report

πŸ”Ž Search Terms

tuple arguments trailing elements contextual type

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

declare function test(
  ...args: [...((arg: number) => void)[], (arg: string) => void]
): void;

test(
  (a) => {
    a
    // ^? actual: any; expected: number
  },
  (b) => {
    b
    // ^? actual: any; expected: number
  },
  (c) => {
    c
    // ^? actual: any; expected: string
  },
);

πŸ™ Actual behavior

Contextual parameters can't be inferred.

πŸ™‚ Expected behavior

Contextual parameters should be inferred.


Quoting @ahejlsberg from here:

This would require us to reason about elements at a fixed offset from the end of a tuple. We currently only reason about elements at a fixed offset from the start. It adds some more complexity, but it is certainly possible to do.

@ahejlsberg ahejlsberg self-assigned this Feb 20, 2023
@ahejlsberg ahejlsberg added the Suggestion An idea for TypeScript label Feb 20, 2023
@ahejlsberg ahejlsberg added this to the TypeScript 5.1.0 milestone Mar 1, 2023
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants