Skip to content

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

Closed
@Andarist

Description

@Andarist

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.

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions