Microsoft/TypeScript

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

Open

#29 531 ouverte le 22 janv. 2019

Voir sur GitHub
 (1 commentaire) (0 réactions) (0 assignés)TypeScript (6 726 forks)batch import
Domain: lib.d.tsExperience EnhancementHelp WantedSuggestion

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

Description

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:

Guide contributeur