Rest inside tuples
- 主要語言
- Rust
- 星號
- 22.3k
- 分支
- 1.9k
- PR 合併指標
- 30 天內沒有已合併 PR
描述
``` 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
貢獻指南
評估
這個 Issue 還沒有評估資料。