Skip to content

type for Function.prototype.bind wrongly preserves fields on a function #34338

Open

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.

Playground Link: http://www.typescriptlang.org/play/?ts=3.7-Beta&ssl=1&ssc=1&pln=7&pc=1#code/MYewdgzgLgBAhjAvDAFASiQPhgbxgXwCg4A6ACwFMAbKkJGAcjIEsHDDRJYAje075mAAmKHPjTtu5arRIQADlWZQUAIlUYA9JpgBVMMDgBXAOZlYAFQCe8igFEATg5AOAXDADCcMGBCwHFHBCMPLOtg5QVowKSlAMMCAAZjBGwhSJghRChEA

Related Issues: #212 seems to be where this was discussed and finally implemented, although it's not directly related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions