microsoft / microsoft/TypeScript
type predicate-ness lost when using Function.prototype.bind
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo l'esempio di TypeScript 3.2.4 con Array.isArray.bind(Array) e confronta il suo comportamento con typescript@next. Traccia il modo in cui Function.prototype.bind preserva le firme delle funzioni e i predicati di tipo; il lavoro è completato quando l'esempio viene compilato senza perdere il tipo del predicato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100