1

I recently had to switch my application from using one DB to another. The new DB provides API driver only in JavaScript but the Node.js, Express backend was written in TypeScript as the previous database provided TypeScript interface drivers.

Now, my dilemma is whether to keep the old TypeScript backend or switch completely to JavaScript. I've read the response beautifully written and explained by @Alluan Haddad Mixing JavaScript and TypeScript in Node.js I had a look at another question and I had a similar response but one of the response mentions it as illegal!! Can I develop Node.js (Express) app in both JavaScript and TypeScript together?

This project is still in development and will be deployed to cloud when ready.

I'd like to know what is the best practice and what I should do ultimately: keep mixed code or switch to JavaScript completely? Kindly help.

Thanks!

kashyap
  • 133
  • 1
  • 10
  • If it is already in typescript why not reverse engineer your used methods and provide a *.d.ts file for the DB declarations and you should be done – joyBlanks Oct 22 '21 at 15:06
  • The only thing you have to do to convert a JS file to TS is to rename it from `.js` to `.ts`. Now you have TS, and additionaly you can start using good stuff like typings (`const a:string; const b:boolean`). If the driver is available in JS, then you should be able to paste whatever JS code in the TS file without problem. – Jeremy Thille Oct 22 '21 at 15:06
  • @JeremyThille Thanks for the quick response. I will try this. – kashyap Oct 22 '21 at 15:17
  • @joyBlanks Do you have a reference or example which I can look up? Thanks. – kashyap Oct 22 '21 at 15:19
  • 1
    I had to use a library called 'smartsheet' and I reverse engineered the calls and came up with this and my calls from the app are now typed. try using generics when you see ambiguity and cast infer type from calls with I use this file smartsheet.d.ts in my app as a declaration type typescript https://gist.github.com/joyblanks/5cd8c26c2efb806032b71bc1f0b5bef4 – joyBlanks Oct 22 '21 at 18:31

0 Answers0