Skip to content
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

Parsing errors when dealing with TypeScript Generics in a type parameter. #2306

Closed
TylorS opened this issue Jun 7, 2022 · 2 comments
Closed

Comments

@TylorS
Copy link

TylorS commented Jun 7, 2022

Hello there!

I'm running into an edge case that seems to be regarding the way esbuild is parsing TypeScript syntax. Here's the real example I was attempting to utilize.

The Code in Question

Screen Shot 2022-06-07 at 10 40 31 AM

The conditions required to trip on this error

The error seems to arise under 2 specific conditions. 1.) The function being called must be an accessed method call on a Namespaced Import or Object/Class in the form of Foo.bar() and 2.) The first type parameter provided to that method must also have its own generics defined for it.

Screen Shot 2022-06-07 at 10 40 43 AM

The Error

Screen Shot 2022-06-07 at 10 55 59 AM

The Workaround

Changing the code to the following will allow things to continue working, which I've gone ahead to use as a workaround for this issue.
Screen Shot 2022-06-07 at 10 52 32 AM

The Reproduction case

I've tried to boil this down to a smaller reproduction case, and this appears to trip up the same exact error.

export declare const Test: {
  readonly service: <F>() => <T extends string>(tag: T) => { service: F; tag: T }
}

export const Foo = Test.service<<A>() => A>()('Foo')
@evanw
Copy link
Owner

evanw commented Jun 7, 2022

Thanks for the report. I haven't investigated yet but I bet it's due to the << token, which needs to sometimes be interpreted as two < tokens instead. Here's a quick workaround that's simpler if you'd like to use it instead:

 export declare const Test: {
   readonly service: <F>() => <T extends string>(tag: T) => { service: F; tag: T }
 }
 
-export const Foo = Test.service<<A>() => A>()('Foo')
+export const Foo = Test.service</**/<A>() => A>()('Foo')

@evanw evanw closed this as completed in 43b8e15 Jun 8, 2022
@mnassabain
Copy link

Recently had a similar problem. Rewriting my functions with the "function" syntax instead of the arrow syntax solved the problem for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants