最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is it bad convention to use .tsx and .js files in the same react application? - Stack Overflow

programmeradmin1浏览0评论

I have a react app with mostly .js files for every ponent. However I would like to use typescript files for a certain group of ponents I am using. Does this cause issues down the road?

I have a react app with mostly .js files for every ponent. However I would like to use typescript files for a certain group of ponents I am using. Does this cause issues down the road?

Share Improve this question asked Jul 25, 2021 at 22:58 AmandaCondaAmandaConda 2434 silver badges18 bronze badges 3
  • 1 Personally, I prefer to use one certain language, is either to use JavaScript Or TypeScript but it is your opinion at the end but I think there is no problem when you use two languages in the same ReactJS project. – Ghost Commented Jul 25, 2021 at 23:07
  • 1 It doesn't cause issues (as TypeScript is essentially a superset of JavaScript), though I'd say it is probably poor practice to use both, as there is really no need to, and you'd have to manage two separate types of files. – Obsidian Age Commented Jul 25, 2021 at 23:08
  • 2 Although I agree it would be better to stick to one language, you can save a lot of time by adding TS and keeping your existing JS code (instead of having to rewrite all your JS to TS). – noahro Commented Jul 25, 2021 at 23:12
Add a ment  | 

1 Answer 1

Reset to default 5

TypeScript works well mixed with JavaScript, it shouldn't be a problem to introduce TypeScript while keeping your existing codebase.

I would say it's a good idea to keep your working JavaScript app, and just add new TypeScript ponents. So you don't have to rewrite your already working JS code.
Later on, when you have time, you can always go back and rewrite your JS to TS.

The only problems I've faced doing this is, when you import JavaScript in your TypeScript, the imported types will often be of type any, which removes the type-safety benefits.

发布评论

评论列表(0)

  1. 暂无评论