-
-
Notifications
You must be signed in to change notification settings - Fork 75
Parse error on arrow function with type parameters #392
Comments
Hmm interesting. It seems like this was a genuine parse error in TypeScript 2.4.x (i.e. nothing to do with this parser) ...but the TypeScript playground, which is using 2.5.x, does not complain. It is odd slightly code in isolation I must say 😄 Do you have a more complete example of the context in which this was used? |
I also cannot seem to reproduce this error on master of this project, using TypeScript Please can you see if you can reproduce? |
Here is my actual use: |
Ah, I see, using it as the value of a declaration makes sense 😄 I figured you couldn't have been using it in isolation like that. Thanks for following up, I will investigate this further |
This must be something to do with your full setup, because your source code does not produce a parse error in the latest version of this parser using TypeScript 2.5.3. As you pointed out, we do already have a fixture which covers this as well. I will see if I can see anything obvious in your setup as a whole. |
It seems like this will need to be investigated in your project https://github.com/mightyiam/eslint-config-standard-with-typescript? Have you tried narrowing down the issue in there and tweaking the config to get the minimal possible repro? It might well be one of the custom rules from eslint-plugin-typescript is the root cause of this... |
I'll do a minimal reproduction PR in this project. |
The following code is all that it takes to trigger the error: <T>(): T => {} The error in this case is:
When I remove from
There is no error. Also, extending from |
A JSX parser... Where? How? |
This seems to avoid the error: "parserOptions": {
"ecmaFeatures": {
"jsx": false
}
} |
It appears to be interpreting the code like this: <T> // JSX opening element
(): T => // raw JSX text
{} // an empty JSX expression container
// [!] missing </T> closing element Given that this error is thrown by the TypeScript parser, it appears to be an issue with TypeScript itself, not just this plugin. |
JSX support in TypeScript is the underlying point here. I can see that the underlying When the TypeScript compiler parses the This is the same reason you cannot use the So yeah, if you want to inherit from that config, you have to accept that you are always in "JSX mode" in TypeScript, working in the same way as if all of your source files were In your original code, even in "JSX mode", the TypeScript compiler is clearly able to determine that the function pickPath<Value> (
path: string,
routes: Routes<Value>,
parentPattern = ''
): Match<Value> { It's possible that the TypeScript team may be able to add in handling for your use-case here, but you would need to report it to them on the main TypeScript repo. It might not be possible. I am going to close this issue as this project is not causing your error. You can either solve it by using unambiguous code (as far as TypeScript in "JSX mode" is concered), or by overriding the parserOptions as you have noted. |
Great job explaining, @JamesHenry. Thank you. |
No worries 😄 Thanks for supporting this project! |
What version of TypeScript are you using?
2.5.3
What version of
typescript-eslint-parser
are you using?8.0.0
What code were you trying to parse?
What did you expect to happen?
Happy happy parse parse. I notice we have this fixture but... error.
What happened?
The text was updated successfully, but these errors were encountered: