microsoft / microsoft/TypeScript

Incorrect type resolution with nested constructors

Aperta
#63,559 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: classes
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione collegata in TypeScript Playground e traccia la risoluzione dei tipi per le due espressioni annidate new class extends .... Il lavoro è completato quando l'esempio riporta B.kind come 'B' invece di 'A' dopo le due estensioni e istanziazioni.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.