-
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
Make default JSX mode "react" #8529
Comments
it is not mandatory. the default is
the extension is used to decide how to parse |
I don't think this is true, unless we've changed it very recently |
Should the default be "React" instead. |
I've been using the new ^ Of course I might be wrong and your judgement is better 🌹 |
FIFY But in all honestly, this is a fantastic solution to this issue. It is opt-in & non-breaking. I for one find the extension |
I don't think this is a good idea. The React syntax is non-standard and may not be compatible with future versions of EcmaScript. Making .tsx optional would seem to couple React with the future of TypeScript for very little benefit. |
There wouldn't be a problem if JSX isn't enabled by default and you must enable it in your |
@donaldpipowitch I see I misunderstood. As long as you have to turn it on, it doesn't seem like a problem. Personally, while I rarely use React, I always use the |
FYI there is a tslint rule to enforce |
@Arnavion Awesome. I'm going to turn it on right now |
We'll make the default JSX mode This should be a super-easy PR if anyone's interested. |
Okay, but can you explain what are the advantages of two syntaxes? Or why using the tsconfig alone for a project is not enough? |
So let's say you have some code like this: let x = <foo>bar;
/* 10,000 lines of code follow */ Or this: let x = <foo>bar;
/* 10,000 lines of code follow */
</foo>; One of these is a file with a JSX tag, and one of these is a file with a type assertion. But we would have to parse 10,000 lines of code to figure that out! This would make interactive editing very slow. The .tsx extension "turns off" the @rozzzly might you provide some feedback along with the 👎 ? |
Ah, I see the reasoning here. My apologies, please disregard my aversion to |
If existing projects are the major problem how about adding another property in the |
i thought you did not like multiple configurations in tsconfig.json to work with JSX/TSX... |
I want one "place" (like a file) to enable JSX for TypeScript, so I can easily share or generate boilerplate for a new project for example. I often see developers (like myself) starting a new project with files using the I didn't count two properties in tsconfig as "multiple configurations" in this case, because they live in the same file and exactly where they belong - in the project configuration file. I dislike having the |
you can always have .tsx only files everywhere. so now you need not worry about boilerplate code setup, you will have to give up on |
Yeah, this works, but only if you have full control over your project. Say you want to share a generic |
if it is a module it should not matter, the compiler will look for both. |
@mhegazy I think that @donaldpipowitch is talking about the |
I want to use "jsx": "preserve", but use *.js extension, since RN not support JSX extension. |
I still like |
@aluanhaddad |
@frogcjn Sorry, I didn't realize they actually rejected a PR to fix it on their end. That is an unfortunate attitude considering the degree of effort from third party developers of both languages (ex: Microsoft: TypeScript) and tools (ex: JetBrains: WebStorm) to support jsx syntax. |
better make extension name configurable, current situation for react-native project:
want to use 'preserve' and get .js file. |
Should this issue be closed? As far as I'm aware you always have to specify the value for the "jsx" flag either in tsconfig.json or through the command line. TS never implicitly sets the "jsx" flag to equal to "preserve". In fact, if you try to compile a .tsx file without specifying the "jsx" option you get an error as such. If you try to compile without specifying the "jsx" option at all you get an error as such: Am I missing something here? |
The topic of this issue was changed. I originally wanted to find a way to drop the It then was changed to what the default value of the jsx setting in the tsconfig should be or so. Not sure what the state of this is. |
Do webpack entry points not use the node resolution algorithm, meaning you can leave the extension off? |
Not in the |
Would pursuing that avenue solve your problem? Making the entry use the node resolution algorithm seems like sensible behaviour. |
Not sure if I understand your question, but the webpack use case with |
Is this issue still open? I'd love to give it a shot, but I have a question.
Do we want to change the default value to "react" but still log an error or change the value and get rid of the error? IMHO allowing to use the default without the error would be a little bit nicer. TypeScript versions I've tested it with are 3.1.2 and my clone of today's master. |
…s per 'foodi-frontend' and microsoft/TypeScript#8529
To enable JSX syntax in TypeScript you need two steps:
"jsx": "react"
to"compilerOptions"
intsconfig.json
.tsx
extensionThis is quite troublesome if you want to reuse certain generators/boilerplates/build scripts for us. It is also against the single source of truth principle and can be confusing. I recently stumbled over a bug where we used the
.tsx
extension, but hadn't configured thetsconfig.json
.There was a lot of discussion recently about changing the
.js
extension to.mjs
to introduce ES6 modules to Node and many people are against that and prefer to have an additional flag in thepackage.json
.I'd like to see the same for TypeScript and JSX:
.tsx
extension is purely optional"jsx": "react"
intsconfig.json
is mandatoryThe text was updated successfully, but these errors were encountered: