typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

Parser divergence: Generic arrow function with function return type

Open DanielRosenwasser opened this issue 2 years ago • 2 comments

const foo = <T>(x: T): (() => T) => {
    return () => x;
}

Expected: No error

Actual

foo.ts:1:18 - error TS1005: ')' expected.

 1 const foo = <T>(x: T): (() => T) => {
                    ~

foo.ts:1:21 - error TS1005: ',' expected.

 1 const foo = <T>(x: T): (() => T) => {
                       ~

foo.ts:1:22 - error TS1134: Variable declaration expected.

 1 const foo = <T>(x: T): (() => T) => {
                        ~

foo.ts:1:24 - error TS1134: Variable declaration expected.

 1 const foo = <T>(x: T): (() => T) => {
                          ~

foo.ts:1:34 - error TS1005: ';' expected.

 1 const foo = <T>(x: T): (() => T) => {
                                    ~~


Found 5 errors in the same file, starting at: foo.ts:1

Also occurs when not parenthesized:

const foo = <T>(x: T): () => T => {
    return () => x;
}

DanielRosenwasser avatar Dec 03 '24 21:12 DanielRosenwasser

Hi, I wanted to check if this issue is still relevant. I believe it has been resolved, I tested it myself and found that it no longer occurs in the latest version.

ongyimeng avatar Mar 18 '25 14:03 ongyimeng

Looks like you're right - thanks @ongyimeng!

DanielRosenwasser avatar Mar 18 '25 17:03 DanielRosenwasser