microsoft / microsoft/TypeScript
type predicate-ness lost when using Function.prototype.bind
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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:
-
Typings for
Function.prototype.bindwere discussed in https://github.com/Microsoft/TypeScript/issues/212 but I couldn't find any mention of type predicates.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das TypeScript 3.2.4-Beispiel mit Array.isArray.bind(Array) nachzustellen und sein Verhalten mit typescript@next zu vergleichen. Verfolge, wie Function.prototype.bind Funktionssignaturen und Typpredikate bewahrt; abgeschlossen ist die Aufgabe, wenn das Beispiel kompiliert, ohne den Prädikattyp zu verlieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100