You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Instantiation expressions should filter overloads by type parameter constraintsΒ #63126
I see the appeal, but I'd be worried about creating an unintended situation where members are silently disappearing. One could also take the position that if an argument is permissible, then it shouldn't be a constraint.
declareconstf: {<T>(x: T): T;new<T>(x: T): Textendsobject ? T : never;// Or if yo don't like `never`, substitute preferred error sentinel};
I get what you're saying, but the two signatures are separate, so each has its own constraint.
Example:
constf: {<T>(x: T): T;new<Textendsobject>(x: T): T;}=functionFuncName<T>(x: T){returnx;}asany;consta=f(1);// ^? const a: 1// Runtime value: 1constb=f(2);// ^? const b: 2// Runtime value: 2constc=f({a: 1});// ^? const c: { a: number; }// Runtime value: { a: 1 }constd=newf(1);// Error: Argument of type 'number' is not assignable to parameter of type 'object'// Runtime value: FuncName { }conste=newf({a: 1});// ^? const e: { a: number; }// Runtime value: { a: 1 }
As you can see in d, when a constructor returns a value which neither an object nor a function, it gets ignored and an actual instance of the constructor is made at runtime.
As you can see in a and b, this only happens when using the function as a constructor, so I would like to express this fact in the type of f
This issue is specifically about instantiation expressions as implemented in #47607. The behavior is apparently as intended, according to #47607 (comment), so this is more like a missing feature than a bug.
I think it is a bug, the documentation states that what I'm asking for should work
To my understanding, it is because it just checks for the number of type arguments, but that's not the expected thing to happen
changed the title [-]Overloads should be filtered by unmet constraints of type parameters[/-][+]Instantiation expressions should filter overloads by type parameter constraints[/+]on Feb 13, 2026
Activity
snarbles2 commentedon Feb 11, 2026
I see the appeal, but I'd be worried about creating an unintended situation where members are silently disappearing. One could also take the position that if an argument is permissible, then it shouldn't be a constraint.
AFatNiBBa commentedon Feb 11, 2026
I get what you're saying, but the two signatures are separate, so each has its own constraint.
Example:
As you can see in
d, when a constructor returns a value which neither an object nor a function, it gets ignored and an actual instance of the constructor is made at runtime.As you can see in
aandb, this only happens when using the function as a constructor, so I would like to express this fact in the type offAFatNiBBa commentedon Feb 11, 2026
Also notice that your workaround doesn't work if the function is not called directly
Even if, probably,
noCtorshould have worked anyway, sinceArray.flatMap()doesn't accept constructors: There's no reason for it to get confusedjcalz commentedon Feb 12, 2026
This issue is specifically about instantiation expressions as implemented in #47607. The behavior is apparently as intended, according to #47607 (comment), so this is more like a missing feature than a bug.
Duplicate of #51694.
AFatNiBBa commentedon Feb 13, 2026
I think it is a bug, the documentation states that what I'm asking for should work

To my understanding, it is because it just checks for the number of type arguments, but that's not the expected thing to happen
RyanCavanaugh commentedon Feb 13, 2026
I think the docs mean compatible by arity only. I'm not sure why it works this way, though
[-]Overloads should be filtered by unmet constraints of type parameters[/-][+]Instantiation expressions should filter overloads by type parameter constraints[/+]