-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: check: Variance RelationshipsThe issue relates to variance relationships between typesThe issue relates to variance relationships between typesHelp WantedYou can do thisYou can do this
Milestone
Description
π Search Terms
instantiation expression caching class expression declaration type arguments type parameter
π Version & Regression Information
- This changed in PR: Cache instantiation expression types early enough to prevent reentrancy during printbackΒ #59931 , cc @weswigham
β― Playground Link
π» Code
class A<T = number> {
value!: T;
child!: InstanceType<typeof A.B<A<T>>>; // this should error
static B = class B<T extends A = A> {
parent!: T;
};
}π Actual behavior
It doesn't error
π Expected behavior
it should error with:
Type 'A<T>' does not satisfy the constraint 'A<number>'.
Type 'T' is not assignable to type 'number'.(2344)
like it did in 5.6: TS playground
Additional information about the issue
The problem here is that the situation is a little bit circular and variances worker gets hits in reentrant manner. The nested call returns emptyArray that is a signal for structuredTypeRelatedToWorker to return Ternary.Unknown.
So checkTypeArguments called by getInstantiatedSignatures doesn't report an error. In the old version of the code, this would be re-called after the variance worker would completely exit and the error would be raised.
I see 2 ways to solve this:
- ignore the introduced caching based
inVarianceComputationto avoid spoiling this - defer
checkTypeArgumentsingetInstantiatedSignatures(well, call it with/*reportErrors*/ falseand defer anoher call with/*reportErrors*/ true)
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: check: Variance RelationshipsThe issue relates to variance relationships between typesThe issue relates to variance relationships between typesHelp WantedYou can do thisYou can do this