microsoft / microsoft/TypeScript
Property 'X' does not exist on type Y
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "does not exist on type"
⏯ Playground Link
Playground link with relevant code
💻 Code
type Listener = {
callback(): boolean;
};
const fn = <T extends Listener>(listener: T) => { };
// this works
fn({
context: new Map<string, number>(),
callback() {
const num = this.context.get('number') ?? 0;
if (num > 0) return true;
else return false;
},
});
// this does not
fn({
context: new Map<string, number>(),
callback() {
const num = this.context.get('number') ?? 0; // Property 'context' does not exist on type 'Listener'.(2339)
return num > 0;
},
});
🙁 Actual behavior
It is giving a compilation error as soon as I change the return variable.
🙂 Expected behavior
Should not give compilation errors.
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 l’esempio collegato di TypeScript Playground e confronta le due chiamate a fn, concentrandoti sul contextual typing e sull’inferenza generica per il valore this del callback. L’issue è completata quando il secondo esempio viene compilato senza l’errore Property 'context' segnalato, preservando il comportamento del primo esempio.
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à
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100