-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Allow JSX without using .tsx
extension
#30503
Comments
Please don't. For a instance 👉 airbnb/javascript#1235 (comment) |
@bricss This is different. TypeScript (and It also doesn't reflect most JSX users opinion about The argument from airbnb/javascript#1235 (comment) is:
But JSX is part of TypeScript. So that argument falls apart in this case. |
A world where half the tools can't figure out what the right way to parse a |
@sindresorhus let fn = <T>(o: T)=> o; // ok in ts parsing error in tsx, <T> is the start of a tag |
The cases I've seen are simply that they only considered the |
IMHO, that should be solved regardless of the outcome of this issue. Even with separate extensions, it's weird that TS and TSX works differently in common cases like this. I don't have a solution. I'm hoping smarter people than me can come up with one. |
Probably a duplicate of #8529. At least that's what I originally wanted as well (but the discussion drifted a little bit away and the title was changed from |
I think the key problem is Of coz, there is another problem, whether we allow non-standard feature in |
@sindresorhus I think smart people did think about this and they did not leave this in because of laziness. The ambiguity is not easy so solve without looking a lot ahead into the stream trying to interpret |
I agree that compiling to
|
Since I use |
It could be enabled with a flag (maybe a By the way, I do not think that enabling and forcing this by default could be a good idea: people developing batch, command line interfaces or back end stuff should not have the risk of outputting jsx related stuff. |
It seems this box shouldn’t be checked. |
@mathiasbynens By default, TypeScript doesn't transform the JSX, so it is correct. |
FYI, most editors also need different grammars for syntax highlighting tsx vs ts (because of the aforementioned ambiguities) and key which to use off of the extension by default. For every tool that doesn't work with .tsx there is, at this point, another tool which wouldn't work without .tsx. I'm not the biggest fan of semantic extensions, but it is a workable solution to the ambiguity issue. |
@weswigham I think the point of the issue is that we wouldn't need different grammars if we dropped the ambiguities. Flow does not have the |
But you're not dropping any ambiguities with this proposal (since |
For your consideration: let fn = <T>(o: T)=> o;
1 < / T >, o // 2 The above code is syntactically valid TS, and, except for the type parameter and annotation on the lambda, syntactically valid JS. In
|
I wasn't aware of this, great example @weswigham, thank you! const jsxInDotTs = (<span>
hello
</span>) An extra brace is still better than not having JSX in |
Please don't open new issues because you didn't like the outcome of prior issues; we cannot sustain a repo where every declined issue just gets re-filed. We read comments in closed issues and are happy to hear additional feedback in #26489 |
Search Terms
JSX, TSX, React, extension
Suggestion
I'm creating a new issue because comments in the closed #26489 issue are ignored, but it's clear that many people want this.
It's annoying having to use a separate file extension just because you want to use JSX. Not all tooling supports the
.tsx
extension. It also means you either need to always use.tsx
if there's a possibility of JSX usage or you need to keep renaming files when you add JSX to them. Neither are good UX.I propose deprecating
<Type>expr
in favor ofas
(as suggested in #26489 (comment)). They do the same thing, butas
is not conflicting with JSX. No point in having duplicate syntax that does the same thing.Alternatively, add a compiler flag to disable
<Type>expr
, which means JSX could be supported for the.ts
extension when this compiler flag is used.Use Cases
Examples
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: