microsoft / microsoft/TypeScript
type for Function.prototype.bind wrongly preserves fields on a function
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TypeScript Playground link and reproduce the shown bind example using the reported TypeScript version. Compare the inferred type of b with JavaScript's runtime behavior; done means the added hello field is rejected on typeof b while valid bind behavior remains supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100