Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Contextually inferred generic function with generic rest parameter not assignable to itselfΒ #43833

Copy link
Copy link
@jcalz

Description

@jcalz
Issue body actions

Bug Report

πŸ”Ž Search Terms

contextual, generic, inference, rest parameter, ts2345

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about generic inference

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

function foo<A extends any[]>(
  arg: <T extends { a: number }>(t: T, ...rest: A) => number
) { }

foo((t, u: number) => t.a)
/* Argument of type
  '<T extends { a: number; }>(t: T, u: number) => number' is not assignable to parameter of type
  '<T extends { a: number; }>(t: T, u: number) => number'.
  πŸ€”πŸ€”πŸ€”
*/

πŸ™ Actual behavior

The compiler infers that (t, u: number) => t.a is of type <T extends {a: number}>(t: T, u: number) => number, but then complains that this type is not assignable to itself (or at least an identically written type). The problem seems to be that the two generic T's can't be unified for some reason.

πŸ™‚ Expected behavior

The compiler should infer the function type as it's doing now, but without futher complaint.


Comes from this Stack Overflow question. I don't really quite get the use case; presumably a real world application would have more than one site where T appears, like <T extends { a: number }>(t: T, ...rest: A) => T, which has the same problem.

Is there an existing issue that mentions this? Is it intended? Limitation? Genuine bug?

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.