Improve 'bind' typing in --strictBindCallApply mode by ahejlsberg · Pull Request #28920 · microsoft/TypeScript (original) (raw)

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:

Fixes #28582.
Fixes #28900.