Skip to content
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

Improve 'bind' typing in --strictBindCallApply mode #28920

Merged
merged 6 commits into from
Dec 10, 2018

Conversation

ahejlsberg
Copy link
Member

With this PR we improve typing of the single-parameter bind method in --strictBindCallApply mode such that generic functions and overloaded functions are more accurately typed (i.e. we improve typing of calls to bind that bind just this and none of the function's parameters). Previously, bind always erased type parameters and propagated only the last overload signature. Now, when calling the single-parameter bind method on a function that has no explicitly declared this parameter (which turns out to be >99% of all observed uses of bind), we simply propagate the function type itself, thus preserving generics and overloads.

The PR introduces two new conditional types in lib.d.ts:

  • ThisParameterType<T>: Extracts the type of the this parameter of T, or 'unknown' if T has no 'this' parameter.
  • OmitThisParameter<T>: Removes the 'this' parameter from T. If T has no explicitly declared this parameter, the result is simply T. Otherwise, a new function type with no this parameter is created from T. Generics are erased and only the last overload signature is propagated in this new function type.

Fixes #28582.
Fixes #28900.

@ahejlsberg
Copy link
Member Author

@DanielRosenwasser We should decided if we want to pull this into a point release or wait for 3.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants