3

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?

8
  • 2
    You can set jsx to "preserve" in your tsconfig.json file. Then when you compile the TS files, the output will retain all of the JSX syntax without the TS-only portions. 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. 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. 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. Commented Jan 16, 2020 at 2:26
  • Why would you want to remove typescript from your project? Commented Feb 16, 2020 at 21:35

2 Answers 2

4

As per my comment, you can set jsx: "preserve" as an option in your TS configuration file, which will make the compiler forego transpiling the JSX into regular JS and output .jsx files you can use. Happy to help!

Sign up to request clarification or add additional context in comments.

Comments

-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.