Skip to content

Argument of type 'string[]' is not assignable to parameter of type '"value" | "value"[]'. #20068

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

Closed
ahagelstein opened this issue Nov 16, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@ahagelstein
Copy link

TypeScript Version: 2.7.0-dev.20171116
Code

const func1 = <T extends (string | number)>(key: string, data: T | T[]): void => {};
const func2 = <T extends (string | number | boolean)>(key: string, data: T | T[]): void => {};

func1("data", ["value"]);
// OK

func2("data", [123, 345]);
// OK

func2("data", [false, true]);
// OK

func2("data", ["123", true]);
// OK

func2("data", ["123"]);
// Argument of type 'string[]' is not assignable to parameter of type '"value" | "value"[]'.
//   Type 'string[]' is not assignable to type '"value"[]'.
//     Type 'string' is not assignable to type '"value"'.

Expected behavior:

Code compiles without errors.

Actual behavior:

Code compiles with error.

BUT: with typescript@2.6.1 there is no error.

@ghost
Copy link

ghost commented Nov 16, 2017

Duplicate of #19837

@ghost ghost marked this as a duplicate of #19837 Nov 16, 2017
@ghost ghost added the Duplicate An existing issue was already created label Nov 16, 2017
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants