How to translate a tsx file to a js file for React

Viewed 12621

I am working on a React Project and have a bunch of tsx files that I want to convert as use as javascript for my project. How should I do that?

2 Answers

I am working on a React Project and have a bunch of tsx files that I want to convert as use as javascript for my project. How should I do that

You can use the typescript compiler e.g.

npx -p typescript tsc somefile.tsx

Ciao, while the web is full of guide on how to translate React Javascript into Typescript, I don't found any reverse guide (so strange...). Anyway, I had same problem some time ago and I found useful get one of those guide JS => TS for React and read backwards. For example, I used this guide. When he said "JavaScript looks like that so you can translate this into Typescript in this way..." I did the contrary (and it worked!). Of course you can skip all the dependencies part. Try and let us know.

Related