-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function.prototype.bind method seems to confuse the compiler #16676
Comments
This could be an instance of #212 and is hard to solve well without something like type operators over the tuples corresponding to parameter lists (as in #5453). As a workaround for your specific issue you could add a declaration like: interface Function {
bind<F extends Function>(this: F, thisArg: any): F
} since you're not passing any initial arguments to the function being bound. |
I'm not sure why you're only seeing this in 2.3.1 - I guess we're not making correct inferences from the In any case, there's definitely a limitation from #212. From both a performance type-safety perspective, you're better off using arrow functions instead of |
Thanks guys for the answer. Eventually I went for the arrow function as suggested by @DanielRosenwasser |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
I recently upgraded from 2.2.1 to 2.3.1 version and suddnely I get a compiling error, which I wouldn't expect at all. Please see code example, and also you can see the error in Typescript playground, http://bit.ly/2rBt43G
TypeScript Version: 2.3.1 / "lib": ["es2015"]
Code
Expected behavior:
I would expect the compiler to infer the type of the function returned by "bind" function
Actual behavior:
It expects the type of the promise returned by "doPromise"
Thanks a lot
The text was updated successfully, but these errors were encountered: