microsoft / microsoft/TypeScript

Incorrect type resolution with nested constructors

Offen
#63,559 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bug Domain: classes
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

🔎 Search Terms

nested constructors type resolution anti-pattern

🕗 Version & Regression Information
  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because I only report bugs to be helpful, but I don't have time to dive deeper myself.
⏯ Playground Link

https://www.typescriptlang.org/play/?#code/KYDwDg9gTgLgBAE2AYwDYEMrDsiA7AZ3gCF0DgAuOAbwCgBIPYAdwAoBKKu++gawEs8CKgHIAgiIaMWHLnAFDRxEXAC+DdetyF4YuAF44TZjgwECcUDGBCLpcjTW1tROMQNGWpshas2EFnrUTsQAdAoIQA

💻 Code
export declare const Base: {
	new(): {
		kind: 'A'
		new(): { kind: 'B' }
	}
}
const A = new class extends Base { }
const B = new class extends A { }
B.kind // shows 'A', but should be 'B'
🙁 Actual behavior

If a ctor returns another ctor, it repeats the first level. In the above example, B.kind is 'A', but since we extended and instantiated twice, it should be 'B'.

🙂 Expected behavior

After extending twice, it should reach the inner class, instead of repeating the outer one.

Additional information about the issue

I can only reproduce this bug with this weird experimental anti-pattern - so on its own probably not a priority at all, but types should probably reflect the runtime state as much as possible, even in weird edge cases such as this, and it might indicate a deeper underlying issue.

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 der verlinkten TypeScript Playground-Reproduktion und verfolge die Typauflösung für die beiden verschachtelten new class extends ...-Ausdrücke. Die Arbeit ist abgeschlossen, wenn das Beispiel B.kind nach den beiden Erweiterungen und Instanziierungen als 'B' statt als 'A' meldet.

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
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

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