I've done some googling, and haven't found a solid answer. In fact, I keep finding the exact opposite answer to my question (i.e., how to migrate TO TypeScript rather than from). As a TS newbie, I'm trying to consider the pros/cons of using it to pitch it to my org. My main question:
If we did adopt TS, what is the level of effort of removing it from a React project if we change our minds later?
My understanding is that TS transpiles to JS. If we wanted to switch to JS later on, we could simply take those transpiled JS files, check them into source, and remove the TS transpiler and files - no more TS. However, React itself has its own conventions that aren't plain JS, so I believe the transpiled files will be JS rather than JSX. Is there a method of transpiling React with TS to React directly that's as effortless as going directly to JS?
I've done some googling, and haven't found a solid answer. In fact, I keep finding the exact opposite answer to my question (i.e., how to migrate TO TypeScript rather than from). As a TS newbie, I'm trying to consider the pros/cons of using it to pitch it to my org. My main question:
If we did adopt TS, what is the level of effort of removing it from a React project if we change our minds later?
My understanding is that TS transpiles to JS. If we wanted to switch to JS later on, we could simply take those transpiled JS files, check them into source, and remove the TS transpiler and files - no more TS. However, React itself has its own conventions that aren't plain JS, so I believe the transpiled files will be JS rather than JSX. Is there a method of transpiling React with TS to React directly that's as effortless as going directly to JS?
Share Improve this question asked Jan 15, 2020 at 15:51 Switch386Switch386 4801 gold badge7 silver badges22 bronze badges 8-
2
You can set
jsx
to "preserve" in yourtsconfig.json
file. Then when you pile the TS files, the output will retain all of the JSX syntax without the TS-only portions. – Chris B. Commented Jan 15, 2020 at 16:22 - @ChrisB. that's perfect. thank you so much. if you want to write an answer, i'll accept it. – Switch386 Commented Jan 15, 2020 at 18:57
- 2 I don't think using the transpiled files as your source files will be a very good idea. I believe typescript does various transformation that aren't the most human readable thing. – Alex Wayne Commented Jan 15, 2020 at 19:46
- 1 Makes sense. Is there another option, or just manual? I saw some library on GitHub that I’m not finding anymore, but it sounded like it wouldn’t work with React anyway. – Switch386 Commented Jan 16, 2020 at 2:26
- Why would you want to remove typescript from your project? – bryan60 Commented Feb 16, 2020 at 21:35
2 Answers
Reset to default 4As per my ment, you can set jsx: "preserve"
as an option in your TS configuration file, which will make the piler forego transpiling the JSX into regular JS and output .jsx files you can use. Happy to help!
the easiest way is to create a new project
steps to do this.
run tsc delete node modules folder
use your terminal to delete all ts files exp: rm -r /.ts or //.tsx
copy the js code to a new react project