facebook / facebook/flow

Rest inside tuples

Đang mở
#2,443 8 bình luận 9 reaction 0 người được giao Xem trên GitHub
feature request Typing: spread Typing: tuple
Ngôn ngữ chính
Rust
Star
22.3k
Fork
1.9k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

``` 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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.