Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when use spread arguments twice #32835

Closed
KSXGitHub opened this issue Aug 13, 2019 · 2 comments · Fixed by #38795
Closed

Error when use spread arguments twice #32835

KSXGitHub opened this issue Aug 13, 2019 · 2 comments · Fixed by #38795
Assignees
Labels
Bug A bug in TypeScript
Milestone

Comments

@KSXGitHub
Copy link
Contributor

KSXGitHub commented Aug 13, 2019

TypeScript Version: 3.5.1

Search Terms:

Code

declare function fn (a: string, b: string, ...c: string[]): void
declare const foo: [string, string, ...string[]]
declare const bar: string[]
fn(...foo) // ok
fn(...foo, ...bar) // error
fn(...foo, ...foo) // error
fn(...bar, ...foo) // error

Expected behavior:

No errors

Actual behavior:

Expected at least 2 arguments, but got 1 or more

Playground Link: link

Related Issues:

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 13, 2019
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Aug 13, 2019
@sandersn
Copy link
Member

sandersn commented Mar 9, 2020

@elibarzilay I think your tuple PR recently fixed this bug. Can you confirm?

@elibarzilay
Copy link
Contributor

#33069 is fixing one aspect of this issue, but there is an additional issue with typechecking the arguments. An example of this:

declare function s2n_ (a: string, b: string, ...c: number[]): void
declare const s2: [string, string]
declare const n_: number[]
s2n_(...s2, ...n_);

fails with

error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.

which is bogus due to code that does not handle spreaded tuples properly. (A fix for that is probably in the loop which is around the middle of getSignatureApplicabilityError.)

@elibarzilay elibarzilay self-assigned this May 21, 2020
elibarzilay added a commit to elibarzilay/TypeScript that referenced this issue May 27, 2020
This completes the work that started in PR microsoft#33069, and fixes microsoft#32835.

There are probably two additional related changes that are needed to
make this more complete:

* Fix the code that composes the error message (see the first two
  `FIXME`s in `callWithSpread3.ts`).

* Fix the code that checks the argument types (second two `FIXME`s).

* There is also an error in `genericRestParameters1.ts` which changed
  but should not be an error in the first place.  Added a `FIXME` there
  too.  (Probably will work if the previous iterm is done.)

In addition, `getEffectiveCallArguments` munges the arguments in case of
a spread in the last argument which might be better to avoid.  (I think
that there are cases where it wouldn't work anyway, such as a spread of
an array followed by a spread of an empty array.)
elibarzilay added a commit to elibarzilay/TypeScript that referenced this issue May 27, 2020
This completes the work that started in PR microsoft#33069, and fixes microsoft#32835.

There are probably two additional related changes that are needed to
make this more complete:

* Fix the code that composes the error message (see the first two
  `FIXME`s in `callWithSpread3.ts`).

* Fix the code that checks the argument types (second two `FIXME`s).

* There is also an error in `genericRestParameters1.ts` which changed
  but should not be an error in the first place.  Added a `FIXME` there
  too.  (Probably will work if the previous iterm is done.)

In addition, `getEffectiveCallArguments` munges the arguments in case of
a spread in the last argument which might be better to avoid.  (I think
that there are cases where it wouldn't work anyway, such as a spread of
an array followed by a spread of an empty array.)
elibarzilay added a commit that referenced this issue Jun 5, 2020
This completes the work that started in PR #33069, and fixes #32835.

There are probably two additional related changes that are needed to
make this more complete:

* Fix the code that composes the error message (see the first two
  `FIXME`s in `callWithSpread3.ts`).

* Fix the code that checks the argument types (second two `FIXME`s).

* There is also an error in `genericRestParameters1.ts` which changed
  but should not be an error in the first place.  Added a `FIXME` there
  too.  (Probably will work if the previous iterm is done.)

In addition, `getEffectiveCallArguments` munges the arguments in case of
a spread in the last argument which might be better to avoid.  (I think
that there are cases where it wouldn't work anyway, such as a spread of
an array followed by a spread of an empty array.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants