microsoft / microsoft/TypeScript

Interface definition utilizing `this` type errors out only in specific cases and only when a member is accessed, not before

Offen
#43,613 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bug Domain: This-Typing Needs Human Review
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

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?

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem verlinkten TypeScript Playground und dem minimalen foo<T>/intersection-Beispiel und reproduziere es über die genannten TypeScript-Versionen 3.8.3, 3.9.7 und 4.2.3 hinweg. Lies den zugehörigen Kontext in den Issues #40928 und im Pull Request #40967; abgeschlossen ist die Aufgabe, wenn das Verhalten konsistent diagnostiziert ist und die gemeldete Regression oder Zirkularität behoben oder klar erklärt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.