3

One of my colleague used typescript for a frontend React project. She is now leaving the company and management has assigned me into this project. They want me to deliver from Day 1, and they are ok with me using Javascript in the project. So how can I use plain Javascript components in a Typescript React project. I understand the advantages of Typescript but right now I do not have time for learning it. So any solutions to the problem would be great.

PS:

  1. We cannot create a new project as it will take time to recreate everything.
  2. For now she made 2 end to end features using Typescript, there are 7 more features to cover and I intend to write them in JS and convert the current 2 features to JS after I am done with the 7 features which are remaining.

I was not able to find any solutions for now

2
  • duplicate the project and keep the original safe, so you won't ruin it later on. try rename all file extension from .ts to .js and run the project. also remove all typescript syntax from all the .ts files before rename to .js. Commented Dec 12, 2022 at 4:33
  • 1
    It depends on the complexity of the project. Typescript and Javascript are very similar these days. Have you tried writing plain javascript and just saving it as .ts files? That might get you there for 80%. The other solution is to downgrade those 2 typescript parts by removing all type information and saving it as .js files. You could do that automatically by using tsc or babel, where the configuration should say that all .ts files have to be saved separately as .js files. It would help if you post some of the code your colleague wrote. Commented Dec 12, 2022 at 4:36

2 Answers 2

2

Add allowJs: true to the tsconfig file. This will allow you to import .js/.jsx files into .ts/.tsx Read more about option

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

Comments

-2

You can basically use Javascript in Typescript since TypeScript is a superset of JavaScript, just find the key differences in both languages (like: writing variables etc.) and you can start coding in Typescript. You can read more here to give you an overview of these differences

1 Comment

not everyone wants to use ts and this isn't what he asked for

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.