microsoft / microsoft/TypeScript
'this' not inferred for immediately invoked .bind()/.call()/.apply()
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der verknüpften TypeScript Playground-Reproduktion und vergleiche die annotierten und nicht annotierten Funktionen, indem du bind, call und apply sofort aufrufst. Verfolge, wie der Compiler die this-Inferenz für diese Aufrufe behandelt; fertig ist es, wenn das nicht annotierte Beispiel den gebundenen Array-Typ ohne den implicit-any-Fehler ableitet und dabei das bestehende Verhalten beibehält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100