microsoft / microsoft/TypeScript
type for Function.prototype.bind wrongly preserves fields on a function
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
When calling bind on a function Javascript does not copy the properties across that have been added to that function, however TS treats them as having been copied.
TypeScript Version: 3.7-Beta
Search Terms: function bind
Code
const a = () => { }
a.hello = 'hi'
const b = a.bind({})
b.hello.split("") // Uncaught TypeError: Cannot read property 'split' of undefined
Expected behavior: hello field should not be present on typeof b.
Actual behavior: hello is deemed to exist on typeof b and the program crashes.
Related Issues: https://github.com/Microsoft/TypeScript/issues/212 seems to be where this was discussed and finally implemented, although it's not directly related.
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 dem TypeScript Playground-Link und reproduziere das gezeigte bind-Beispiel mit der gemeldeten TypeScript-Version. Vergleiche den inferierten Typ von b mit dem Laufzeitverhalten von JavaScript; die Aufgabe ist abgeschlossen, wenn das hinzugefügte hello-Feld bei typeof b abgelehnt wird, während gültiges bind-Verhalten weiterhin unterstützt wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100