microsoft / microsoft/TypeScript
Interface definition utilizing `this` type errors out only in specific cases and only when a member is accessed, not before
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.3k
- Merge moyen
- 2 j 4 h
- PR mergées (30 j)
- 132
Description
Bug Report
🔎 Search Terms
"interface this"
"interface this" intersection
"is referenced directly or indirectly"
"is referenced directly or indirectly in its own type annotation."
ts(2502)
HKT circular
intersection circular
🕗 Version & Regression Information
- This changed between versions 3.8.3 and 3.9.7
⏯ Playground Link
Playground link with relevant minimal code and commented version
💻 Code
With version 4.2.3
interface foo<T> { a: T; b: this["a"] };
// ^- 'b' is referenced directly or indirectly in its own type annotation.ts(2502)
type intersection = foo<string> & foo<number>; // Works in some cases, shown in linked playground
type induces_error = intersection["a"]; // Comment this out and the error in the interface goes away
Found when messing with ways to simulate HKTs with this type, which itself seems to be considered a valid use case, per:
https://github.com/microsoft/TypeScript/issues/40928 https://github.com/microsoft/TypeScript/pull/40967
🙁 Actual behavior
- Interface definition erroring out for an unclear reason when using said interface later down the line, but not before. It doesn't seem right that the definition shows an error that wasn't there before by just accessing a property.
- Error itself is questionable, worked in 3.8.3, and a similar use case seems to be covered by the test (#40967) linked above?
🙂 Expected behavior
- Interface definition either always errors, or an error doesn't pop up only when using the interface definition only in specific ways.
- Additionally, reason for circularity error is not immediately obvious to me, and it seems it might a regression since 3.8.3?
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par le TypeScript Playground lié et l’exemple minimal foo<T>/intersection, en le reproduisant avec les versions de TypeScript mentionnées 3.8.3, 3.9.7 et 4.2.3. Lisez le contexte associé dans les issues #40928 et la pull request #40967 ; c’est terminé lorsque le comportement est diagnostiqué de manière cohérente et que la régression ou la circularité signalée est résolue ou clairement expliquée.
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é
- Active
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100