[英]How to translate a tsx file to a js file for React
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.我正在开发一个 React 项目,并且有一堆 tsx 文件,我想将它们转换为我的项目的 javascript 使用。 How should I do that?
我该怎么做?
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.
我正在开发一个 React 项目,并且有一堆 tsx 文件,我想将它们转换为我的项目的 javascript 使用。 How should I do that
我该怎么做
You can use the typescript compiler eg您可以使用 typescript 编译器,例如
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...). Ciao,虽然 web 充满了如何将 React Javascript 翻译成 Typescript 的指南,但我没有找到任何反向指南(真奇怪......)。 Anyway, I had same problem some time ago and I found useful get one of those guide JS => TS for React and read backwards.
无论如何,前段时间我遇到了同样的问题,我发现获取这些指南 JS => TS for React 并向后阅读是有用的。 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.).
当他说“JavaScript 看起来像那样,所以你可以用这种方式将它翻译成 Typescript ......”我做了相反的事情(而且它奏效了。)。 Of course you can skip all the dependencies part.
当然,您可以跳过所有依赖项部分。 Try and let us know.
尝试让我们知道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.