π Search Terms
variance class expression instantiation reference
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240812#code/MYGwhgzhAECCA8AVaBeaA7ArgWwEYFMAnAPmgG8AoaaANzBE3wEIAuaRAbiumAAsBLEABNW0AC4BPAA74A9gDM4AOgBC8BImLEO0APS7oRQrMIRufQUIBMoyTIXK1GrTv3QIYbPmiQfuWTTeuJhi0EKy+BDoAOShRiYU3BBiYGL8wNAqqDzgUJlIhgAeYvjoQjCw2bCklNTUUmCEpWKinNwAvlztiaCQFVYFaFh4RDXcdAzMbG3UFsK20nKKsFaq6gPDBCTa5gLCNmx2S3CrTgOa2noGHl4+FUpzQtAAFGBlyo9WAJTQwaHhkRicUIxkIiWoyVS6Uy2V6eTUyHwxVK5ROVSsYzq0AaTXQLWmXGonQo3SAA
π» Code
class A<T = number> {
value!: T;
child!: typeof A.B<A<T>>; // errors
child2!: typeof A.B<A<T>>; // same as above but doesn't error
static B = class B<T extends A = A> {
parent!: T;
};
}
class A2<T = number> {
value!: T;
child!: typeof A2.B<A2<number>>;
child2!: typeof A2.B<A2<T>>; // same as A.child (and A.child2) but doesn't error
static B = class B<T extends A2 = A2> {
parent!: T;
};
}
π Actual behavior
child2 in both classes is free of errors
π Expected behavior
both child2 properties should contain errors (like child in A)
Additional information about the issue
This is related to the fact that child2 reenters getVariancesWorker for the same symbol, so it returns with emptyArray that was eagerly set as links.variances on the first entry of this function. This, in turn, is a signal for structuredTypeRelatedToWorker to return Ternary.Unknown.
Since this is truly a circular situation, I think this is effectively a design limitation. I'm only reporting this for documentation purposes.
π Search Terms
variance class expression instantiation reference
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240812#code/MYGwhgzhAECCA8AVaBeaA7ArgWwEYFMAnAPmgG8AoaaANzBE3wEIAuaRAbiumAAsBLEABNW0AC4BPAA74A9gDM4AOgBC8BImLEO0APS7oRQrMIRufQUIBMoyTIXK1GrTv3QIYbPmiQfuWTTeuJhi0EKy+BDoAOShRiYU3BBiYGL8wNAqqDzgUJlIhgAeYvjoQjCw2bCklNTUUmCEpWKinNwAvlztiaCQFVYFaFh4RDXcdAzMbG3UFsK20nKKsFaq6gPDBCTa5gLCNmx2S3CrTgOa2noGHl4+FUpzQtAAFGBlyo9WAJTQwaHhkRicUIxkIiWoyVS6Uy2V6eTUyHwxVK5ROVSsYzq0AaTXQLWmXGonQo3SAA
π» Code
π Actual behavior
child2in both classes is free of errorsπ Expected behavior
both
child2properties should contain errors (likechildinA)Additional information about the issue
This is related to the fact that
child2reentersgetVariancesWorkerfor the same symbol, so it returns withemptyArraythat was eagerly set aslinks.varianceson the first entry of this function. This, in turn, is a signal forstructuredTypeRelatedToWorkerto returnTernary.Unknown.Since this is truly a circular situation, I think this is effectively a design limitation. I'm only reporting this for documentation purposes.