0

I've recently started working on a new project at work which has been utilizing React and JavaScript.

As someone who mainly used TypeScript in previous projects I've been struggling a bit with how loose everything is.

If I were able to, I would just convert the whole project to TypeScript however some of my coworkers aren't familiar with it.

My question is, lets say for example, I needed to add a new component somewhere on the page, would it work if I added TypeScript to the project with npm and had only one file as .tsx? Of course when building the project for production I would run TSC to compile it back into vanilla JS.

Also thought I should just point out I’m not looking to convert the whole project to TypeScript, just a few here and there.

Thanks!

5
  • with just a few changes in your config this is easily possible. Just changed my whole project to typescript file by file over 5 weeks. :) Commented Mar 24, 2022 at 15:00
  • read this: sitepoint.com/how-to-migrate-a-react-app-to-typescript Commented Mar 24, 2022 at 15:01
  • This is available here: add typescript to existing react app Commented Nov 14, 2022 at 2:05
  • @ffx292 did you found any suitable answer? cause none of the answers / comments works for me Commented Jul 19, 2023 at 12:12
  • I found that just simply switching the react project over to Typescript, and then in the tsconfig file, selecting the option allowJs, works. When you npm run, it'll compile both ts and js files, that was how I just slowly changed it over. Commented Jul 20, 2023 at 0:30

1 Answer 1

1

Set up your project as if you were going to convert everything to typescript, make sure you have allowJs and checkJs set to true in your tsconfig file, make sure all variations of TS strict mode are off, then convert as many or as few (or even none) js files to ts.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.