microsoft / microsoft/TypeScript

Mixing base class defeats circularity protection

Ouverte
#61,721 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Domain: check: Type Circularity Help Wanted Possible Improvement
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
2 j 4 h
PR mergées (30 j)
132

Description

### 🔎 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

- This changed in the PR #39675

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

```ts
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(
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_

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par la reproduction liée dans TypeScript Playground et suivez les diagnostics de circularité pour l’expression de base de mixin calculée et son type de retour d’intersection. C’est terminé lorsque le modèle de mixin présenté, y compris le cas utile d’un mixin non vide, ne produit aucune erreur erronée de base récursive ou d’annotation autoréférentielle.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
typescript
Domaine
compilers
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.