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
1 Answer
Reset to default 5TypeScript 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.