microsoft / microsoft/TypeScript
'this' not inferred for immediately invoked .bind()/.call()/.apply()
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
function type inferrence, function apply function, function call function
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about type inference
⏯ Playground Link
Playground link with relevant code
💻 Code
let f2 = function(this: number[]) {
console.log(this)
}.bind([1, 2, 3]);
// ^^ works fine
let f1 = function() {
console.log(this)
// ^^ 'this' implicitly has type 'any' because it does not have a type annotation.
}.bind([1, 2, 3]);
🙁 Actual behavior
Compiler shows an error: "'this' implicitly has type 'any' because it does not have a type annotation."
🙂 Expected behavior
The type of this to be correctly infered from the bind, call or apply call.
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 la riproduzione collegata di TypeScript Playground e confronta le funzioni annotate e non annotate usando bind, call e apply invocati immediatamente. Traccia la gestione da parte del compilatore dell’inferenza di this per queste chiamate; il lavoro è completato quando l’esempio non annotato inferisce il tipo di array associato senza l’errore implicit-any, mantenendo il comportamento esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100