How do I convert TSX to JSX

Viewed 14555

I have a project where I wrote some new code in Expo with TypeScript (since I am more used to having a type safe language). However, I want to port what I wrote to something that was written with Expo with JavaScript.

I can manually just strip off the types as I go along to solve the problem, but I was wondering if there's a more automatic way of doing it. I know typescript eventually compiles down to JavaScript but I want to keep the HTML embedded code the same when I do the conversion. Is it possible?

2 Answers

The answer provided by @Jason is close to what I needed.

In the end I ran this command

npx tsc --jsx preserve -t es2020 --outDir js --noEmit false

This generated the .js and .jsx files in the js folder which can be copied over to non-typescript systems.

--noEmit false is needed for the Expo generated tsconfig.js which is noEmit: true

The -t es2020 generates output using ES2020 standards so you can get import and export along with the async await intact.

Related