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

type predicate-ness lost when using Function.prototype.bind #29531

Open
mheiber opened this issue Jan 22, 2019 · 1 comment
Open

type predicate-ness lost when using Function.prototype.bind #29531

mheiber opened this issue Jan 22, 2019 · 1 comment
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@mheiber
Copy link
Contributor

mheiber commented Jan 22, 2019

TypeScript Version: 3.2.4 or @next as of 2019-01-22

Search Terms:

Code

const isArray: typeof Array.isArray = Array.isArray.bind(Array);

Expected behavior:
Compiles.

Actual behavior:

Error message:

error TS2322: Type '(arg: any) => boolean' is not assignable to type '(arg: any) => arg is any[]'.
  Signature '(arg: any): boolean' must be a type predicate.

What seems to be happening is that the type predicate-ness of Array.isArray is lost when .bind is used. I tested with a few type predicate functions, and always get the same error.

Playground Link:

Not reproducible on playground, because it depends on a higher TS version.

In the playground, the type of the RHS is any, so there is no compilation error.

Related Issues:

@weswigham weswigham added Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Experience Enhancement Noncontroversial enhancements labels Jan 23, 2019
@weswigham
Copy link
Member

AFAIK, this should be fixable with some predicate-y overloads for the strictBindCallApply types in lib.d.ts.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Help Wanted You can do this labels Jan 23, 2019
@RyanCavanaugh RyanCavanaugh added this to the Community milestone Jan 23, 2019
@RyanCavanaugh RyanCavanaugh modified the milestones: Community, Backlog Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants