Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Union types not correctly handled in array.map #30271

Copy link
Copy link
@Roaders

Description

@Roaders
Issue body actions

TypeScript Version: playground / 3..3.333

Search Terms:
union type, array map

Code

function flattenStringArrays(values: string | string[] | string[][]): string{

    if (Array.isArray(values)) {
        return values.map(value => flattenStringArrays(value)).join("");
    } else {
        return values;
    }
}

Expected behavior:
here the value in the map expression should be of type string[] | string[][]

Actual behavior:
Compilation error thrown:

Cannot invoke an expression whose type lacks a call signature. Type '((callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[]) | ((callbackfn: (value: string[], index: number, array: string[][]) =>
U, thisArg?: any) => U[])' has no compatible call signatures.

Playground Link:
link

Related Issues:

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdAn existing issue was already created

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.