Skip to content

Mixing base class defeats circularity protection #61721

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

Open
LukeAbby opened this issue May 18, 2025 · 0 comments
Open

Mixing base class defeats circularity protection #61721

LukeAbby opened this issue May 18, 2025 · 0 comments
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@LukeAbby
Copy link

🔎 Search Terms

mixin, referenced directly or indirectly in its own type annotation, recursively references itself as a base type, referenced directly or indirectly in its own base expression.

🕗 Version & Regression Information

Given that this was when base types were consistently checked for errors this has effectively existed forever, just only started being reported in #39675.

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEkoGdnwEIpAYQPYFsAjKAFygDsT4BvAKHkV3ORJgFcwTcYAKAOgGwA5sgBc8ANp4ipCiQkAiAA4xcShQF0NASgDc9eAHpDDU2fNmAetZu271+AHJhyR-ACWaOADMQccmAgwPDA7nCcEACe8Nwe5KHhJFFxHiRouADu5PAkkUoIFOS4ZCTuTHy0AL60tKBIcIjQqPAAkpR+5FAQ2BDuIJQAIrhgbPj9VHQMYEws7Jzc-IIwIuIUkRI6+tW14NAN3mwBpUzwPX2Dw6PjALLuAB7u5AA8mMg4TcgAfDwGryDifx6KGQtG04ly+Vw3la7RgnW6vXGQxGY0o8AAZBgsEDUPpjPBLPAAEogfC4ABuCAABhCQFCYSQOl0zkjLqiSFT4BRgiQABYIMBhEZ7dy5eBCXAgNBQDJQSIVHb1AUfU4EYhkNEgO6M+JoFkXFE3e6PHiAtWySjaGgGfEWcz2QkAFTyCEc0nVcjc4TYMGQ7kpyR8fn6gTQoreEGhKC58GIbxyLoqDFtdtMDqc7otJDcnngQf8gWCCXASWisUexYi0UeqXSWVjWHgWpUUr95QMKjU4nIo0Ifi2NSAA

💻 Code

declare class BaseCombatant {
  constructor(...args: [Combatant["prop"]]);
  //                  ^^^^^^^^^^^^^^^^^ 'args' is referenced directly or indirectly in its own type annotation.
}

declare class InternalClientDocument {
  constructor(...args: any[]);
}

declare function ClientDocumentMixin<BaseClass>(
  Base: BaseClass
): typeof InternalClientDocument & BaseClass;
// ^ Remove `typeof InternalClientDocument` and the circularity goes away.

declare class Combatant extends ClientDocumentMixin(BaseCombatant) {
  //            ^^^^^^^ Type 'Combatant' recursively references itself as a base type.
  //            ^^^^^^^ 'Combatant' is referenced directly or indirectly in its own base expression.
  prop: number;
}

🙁 Actual behavior

Numerous errors.

🙂 Expected behavior

No error. This pattern is not intractable, in fact if you remove the useless typeof InternalClientDocument in typeof InternalClientDocument & BaseClass it works.

In reality I'm actually dealing with a useful mixin, not an empty class, so I would prefer this to work for a complete mixin as well. I'm guessing the issue has something to do with weaker caching around arbitrary expressions as the base class compared to the typical base class with a concrete name.

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels May 19, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
Development

No branches or pull requests

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy