microsoft / microsoft/TypeScript
Interface definition utilizing `this` type errors out only in specific cases and only when a member is accessed, not before
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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?
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con il TypeScript Playground collegato e con l’esempio minimo foo<T>/intersection, riproducendolo nelle versioni di TypeScript menzionate 3.8.3, 3.9.7 e 4.2.3. Leggi il contesto correlato nelle issue #40928 e nella pull request #40967; il lavoro è completato quando il comportamento è diagnosticato in modo coerente e la regressione o circolarità segnalata è stata risolta o chiaramente spiegata.
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à
- Attiva
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100