简体   繁体   中英

Migrating away from Typescript in a React project

I've done some googling, and haven't found a solid answer. In fact, I keep finding the exact opposite answer to my question (ie, 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?

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM