facebook / facebook/flow

Rest inside tuples

Aperta
#2,443 8 commenti 9 reazioni 0 assegnatari Vedi su GitHub
feature request Typing: spread Typing: tuple
Lingua principale
Rust
Stelle
22.3k
Fork
1.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

``` js
type restStartTuple = [...number, string];

(["2"]: restStartTuple);
([1, "2"]: restStartTuple);
([1, 2, "3"]: restStartTuple);

([1, 2, 3]: restStartTuple); // FlowError
([1, "2", 3]: restStartTuple); // FlowError

type restMiddleTuple = [string, ...number, string];

(["1", "2"]: restMiddleTuple);
(["1", 2, "3"]: restMiddleTuple);
(["1", 2, 3, "4"]: restMiddleTuple);

(["1"]: restMiddleTuple); // FlowError
(["1", 2]: restMiddleTuple); // FlowError
([1, 2, 3]: restMiddleTuple); // FlowError
(["1", "2", "3"]: restMiddleTuple); // FlowError
```

The primary use case is to support rest arguments in functions in other positions (i.e. `func(...a, b)`)

This syntax would be most natural to people:

``` js
function restStart(...a: Array, b: string) {...}
function restMiddle(a: string, ...b: Array, c: string) {...}
```

However, since JavaScript does not support that kind of syntax we need a workaround. I would suggest this:

``` js
function restStart(...args: [...Array, string]) {...}
function restStart(...args: [string, ...Array, string]) {...}
```

So really there's two feature requests here: Support for rest inside tuples and for them to work with function arguments.

The current work around is to create libdefs with a bunch of possible combinations like here: https://github.com/flowtype/flow-typed/pull/260

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.