-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Support .tsx
file extensions.
#56322
Comments
Would you like to send a PR? |
Before working on it, I would like to discuss and reach consensus that the Node.js maintainers would like to include this feature. |
I'm not sure what there is to discuss, but in any case, it won't happen until someone submits a PR. //cc @nodejs/typescript |
I see, so from my perspective here is what I think we need consensus on:
imho this would solve the outlined problem for most users, but some might have a desire to support JSX directly in the future in some form. |
Many of the arguments cited in favour seem illogical to me. It seems like you're suggesting supporting a mismatched file extension and then erroring when the file extension is used correctly? Supporting actual TSX would be quite a hairy ordeal, and encouraging people to misuse the Or have I misunderstood you? |
Yes, you misunderstood. Using the |
It seems I did not. That is a misuse of the file extension, and it would be a landmine for users. We should absolutely not do that. However, if we were to support jsx and thus tsx, that would be a different story. One would need to figure out how to handle configuration, because jsx has multiple transpile options. I could see value in that, but I would advise first sketching out some broad-strokes before jumping to a PR (which would almost certainly result in contradicting opinions). Far better to get those to consensus before churning on an implementation. Happy to answer questions for that 🙂 I don't know the appetite of others (I'm not sure of my own opinion on it) to support jsx though. |
How is it not a misuse of a file extension to do that? That's what |
There are many projects with files that use the On the topic of partial support, Node.js implemented |
It seems to me that supporting files with a
This proposal is more like saying “why not support the |
I explored this idea but I'm against it. |
Would you mind elaborating on this sentence? |
If types are removed, all its left is jsx that cannot be run without an external loader or a framework (that uses a loader) |
The logical approach, considering the previously discussed While I agree with adding support for Introducing a new flag might seem exhaustive, but it aligns with the established decision-making process. Moreover, the JSX implementation should remain independent of TypeScript-specific features, much like how This involves two distinct steps:
Providing only one of these features without the other is both counterintuitive and likely to confuse users. |
A potential first step toward this approach could be to simply ignore If this change is released with a clear note explaining that it currently ignores This would provide a practical and usable solution much earlier, giving developers a path forward without having to wait for the complete implementation of a |
I'd first try to get consensus for jsx support, if that happens adding type stripping to tsx is easy. |
The opposite would allow jsx usage via custom loaders, waiting for jsx support means no jsx at all until that + it would bring more people to use |
What is the problem this feature will solve?
Node's
--experimental-strip-types
and--experimental-transform-types
are great improvements that allow us to drop a lot of tooling to run TypeScript in node. Right now, it only supports the.ts
extension and does not work on.tsx
..tsx
only really exists because of syntax ambiguity with a (somewhat legacy) way of typecasting in.ts
files: microsoft/TypeScript#26489 (comment)Why would you use
.tsx
for backend code?In a monorepo, you might have many packages shared by the client and backend. For consistency, those projects may want to use only a single file extension like
.tsx
. If you use React, which many people do, and some files use.ts
and some.tsx
, it's always jarring to type JSX in a.ts
file, realize it's a syntax error, and then having to rename the file. The renames also make it harder to navigate git history. Finally, if you are using only a single extension, TypeScript's behavior is always the same with regards to how angle brackets work.I'd be excited to implement this feature and send a Pull Request if the Node.js team is in favor of supporting
.tsx
extensions.What is the feature you are proposing to solve the problem?
I imagine the most workable solution is to support
.tsx
extensions just like.ts
, but throw an error if JSX is actually used. I'm not advocating for supporting JSX, just for node to support.tsx
files without compiling JSX.What alternatives have you considered?
The alternatives are to keep using third-party tooling to strip TypeScript types, or to rename all backend files using
.tsx
to.ts
, which may not be possible in large monorepos given the amount of files affected, and as mentioned previously, makes git history more cumbersome to work through.The text was updated successfully, but these errors were encountered: