Skip to content

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

Closed
@ahagelstein

Description

@ahagelstein

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions