Skip to content

generic arrow functions are incorrectly identified as JSX elements #15785

Closed
@mutsys

Description

@mutsys

TypeScript Version: 2.3.2

Code

this statement causes an error

const foo = <P>(bar: P): void => {
    console.log(bar);
};

while the equivalent statement written with the function keyword does not:

function foo<P>(bar: P): void {
    console.log(bar);
}

it seems that as long as there is some other statement that precedes the generic declaration, the statement is recognized as valid. this next example is also recognized as valid:

const foo = (): <P>(bar: P) => void => {
    return function<P>(bar: P): void {
        console.log(bar);
    };
}

however, changing the inner function to an arrow function also results in the same error.

Expected behavior:
the expression is evaluated and recognized as valid

Actual behavior:
an error is produced:

[ts] cannot find name 'P'.
[ts] JSX element 'P' has no corresponding closing tag.

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