-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Needs More InfoThe issue still hasn't been fully clarifiedThe issue still hasn't been fully clarified
Description
Bug Report
π Search Terms
- generic type prototype inference
π Version & Regression Information
- This changed between versions 4.7.4 and 5.2.0
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
prototype
β― Playground Link
Playground link with relevant code
π» Code
interface Type<T> {
new(...args: any[]): T;
}
interface Proto<T> {
prototype: T;
}
function injectWithType<T>(a: Type<T>): T { return null as T };
{
const okUnknown = injectWithType(Set); // Set<unknown> β οΈ
const okNumber = injectWithType<Set<number>>(Set); // Set<number> β
const okNumber2 = injectWithType(Set<number>); // Set<number> β
}
function injectWithProto<T>(a: Proto<T>): T { return null as T };
{
const okAny = injectWithProto(Set); // Set<any> β οΈ
const okNumber = injectWithProto<Set<number>>(Set); // Set<number> β
const unexpectedAny = injectWithProto(Set<number>); // Set<any> βΌοΈ
}
The compiled version has a bug too - double parentheses (reproduced both with the injectWithType
and the injectWithProto
.):
const unexpectedAny = injectWithProto((Set)) // >= [email protected]
const unexpectedAny = injectWithProto(Set()) // < [email protected]
π Actual behavior
When using an interface
or atype
with the prototype
property to declare class, generic type is getting wrong, especially in the ExpressionWithTypeArguments
(βΌοΈ)
case.
π Expected behavior
(β οΈ)
- These lines should have the same type (Set<any>
or Set<unknown>
)
(βΌοΈ)
- This line should correctly infer generic type (Set<number>
)
const arrOfNum = injectWithProto(Set<number>) // should be Set<number>, not Set<any>
WaveMeUp
Metadata
Metadata
Assignees
Labels
Needs More InfoThe issue still hasn't been fully clarifiedThe issue still hasn't been fully clarified