Commit 8657dc1
committed
Error on excess spread arguments
Make the *technically* correct construction illegal:
```ts
declare function f(n: number): void;
declare var ns: number[];
f(1, ...ns);
```
This call only makes sense if `ns = []`, but in that case, why pass
`ns` at all? Allowing this call masks other errors when functions are
refactored to have fewer parameters, or to stop using rest parameters:
```ts
declare function old(...ns: number[]): void;
declare function new(ns: number | number[]): void;
old(1, ...ns); // Fine!
new(1, ...ns); // Should error!
```
This change the error for excess spread arguments to be more
understandable:
"Expected 3 arguments, but got least 4".
Previously the error would have been
"Expected 3 argument, but got at least 3", which is, again, technically
correct, but not understandable.1 parent d49491b commit 8657dc1
1 file changed
Lines changed: 7 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15790 | 15790 | | |
15791 | 15791 | | |
15792 | 15792 | | |
15793 | | - | |
15794 | | - | |
| 15793 | + | |
15795 | 15794 | | |
15796 | | - | |
| 15795 | + | |
| 15796 | + | |
15797 | 15797 | | |
15798 | 15798 | | |
15799 | 15799 | | |
| |||
16501 | 16501 | | |
16502 | 16502 | | |
16503 | 16503 | | |
16504 | | - | |
| 16504 | + | |
| 16505 | + | |
| 16506 | + | |
| 16507 | + | |
16505 | 16508 | | |
16506 | 16509 | | |
16507 | 16510 | | |
| |||
0 commit comments