Skip to content

Non-first occurrence of circular class instantiation is always silently allowed #59606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Andarist opened this issue Aug 12, 2024 · 1 comment
Labels
Not a Defect This behavior is one of several equally-correct options

Comments

@Andarist
Copy link
Contributor

πŸ”Ž 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.

@RyanCavanaugh RyanCavanaugh added the Not a Defect This behavior is one of several equally-correct options label Aug 13, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not a Defect This behavior is one of several equally-correct options
Projects
None yet
Development

No branches or pull requests

3 participants