Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Parsing error for generic function with index signature return type #393

Closed
OliverJAsh opened this issue Oct 16, 2017 · 5 comments
Closed
Labels

Comments

@OliverJAsh
Copy link

What version of TypeScript are you using?
2.4.1

What version of typescript-eslint-parser are you using?
8

What code were you trying to parse?

const x = <T>(): { [x: string]: string } => ({});

What did you expect to happen?
No error

What happened?

[eslint] Parsing error: ',' expected.
@JamesHenry
Copy link
Member

I believe this behaviour is correct.

The source you have provided is genuinely a parse error in TypeScript 2.4.x:

http://astexplorer.net/#/gist/69f89d5c7455a7713684a53d49bdf7b1/67a4d6d0992298f9840e1b8fefe601c101ae3e40

(See the parseDiagnostics array)

In 2.5.x it seems to produce a valid AST with this parser. Please feel free to reopen if you have any more information.

@OliverJAsh
Copy link
Author

OliverJAsh commented Oct 23, 2017

The example is valid in TypeScript 2.4 and 2.5 only for .ts extensions—not when JSX is enabled, e.g. .tsx). I believe astexplorer.net is enabling JSX.

You can try it here: https://github.com/OliverJAsh/typescript-eslint-parser-parse-error-test

Therefore I do believe the example above should not produce an ESLint parse error for non-JSX files, i.e. .ts.

@OliverJAsh
Copy link
Author

OliverJAsh commented Oct 23, 2017

Here is an example of the error occurring inside a non-JSX (.ts) file (updated):
image

@JamesHenry
Copy link
Member

Ah yes you are right and this then is the same case as the one I dug into yesterday:

#392 (comment)

As outlined in that comment, you will need to disable jsx in your ESLint config or use constructs which are not ambiguous for TypeScript when in "JSX mode".

I have opened an issue to see if we can make the setting inferrable from file extension in the long run: #399

@OliverJAsh
Copy link
Author

Thank you, that makes sense!

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

No branches or pull requests

3 participants