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

Investigate the possibility of setting jsx: true based on file extension #399

Closed
JamesHenry opened this issue Oct 23, 2017 · 4 comments
Closed

Comments

@JamesHenry
Copy link
Member

JamesHenry commented Oct 23, 2017

In this parser we have to use the parserOptions.jsx flag to determine whether or not to configure the actual TypeScript compiler to parse the source as JSX.

When the TypeScript compiler parses certain syntax in "JSX mode" it is ambiguous and could be a JSXElement as far as it's concerned.

This is the same reason you cannot use the <> syntax for type assertions in TSX files, you have to use the as syntax.

Essentially then, if you want to have jsx: true, 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 .tsx, and so you cannot use any ambiguous constructs.

Right now the DX is not at all clear when you have configured jsx: true in your ESLint config and then use ambiguous TypeScript constructs. You will just end up with a random parse error from the TypeScript compiler.

Ideally, we would be able to provide clearer error messaging, or infer the jsx setting itself from the file extension (.ts vs .tsx)

This would have avoided the need for users to report:

#392
#393

@JamesHenry
Copy link
Member Author

We can look at addressing the AST for this in the new parser project: https://github.com/JamesHenry/typescript-estree

@OliverJAsh
Copy link

Is it worth filing an issue on that project so we don't forget to include (or continue tracking) this?

@JamesHenry
Copy link
Member Author

Thanks @OliverJAsh, ported here JamesHenry/typescript-estree#9

@OliverJAsh
Copy link

Fixed by #543?

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

Successfully merging a pull request may close this issue.

2 participants