3 ms·
Okay I'm finally ready to take a shot at TS. Any suggestions on the best guide for "incrementally, politely, unopinionatedly introducing TS to an existing JS w
by Waterluvian 8y ago
Okay I'm finally ready to take a shot at TS.
Any suggestions on the best guide for "incrementally, politely, unopinionatedly introducing TS to an existing JS web application"?
Last time I gave it a shot I had to make a lot of changes upfront so I walked away from it.
- DanRosenwasser 8y agoAdd a `tsconfig.json` and turn on `allowJs` for starters. If you're already using Babel, you can check out the Babel/TypeScript Starter for some guidance on quick and easy integration [1]. Then create a `types.ts` file for types that are used throughout your project, and as you see common data structures being used in your program, declare `interface`s and `type` aliases there. Then you can switch your `.js` files to `.ts`/`.tsx` files one-by-one and add types (or even add types via JSDoc and then convert those to `.ts` files when you're ready). Eventually for the best experience, you can start switching on strictness modes. `strictNullChecks` is a pretty great one to use early on. Then `noImplicitAny` and `noImplicitThis` when you have pretty good type coverage. Finally you can turn on the full `strict` flag which will turn the others on, which are pretty easy to integrate into your codebase (and which you can turn off individually). [1]: https://github.com/Microsoft/TypeScript-Babel-Starter https://github.com/Microsoft/TypeScript-Babel-Starter
- Waterluvian 8y agoWow thanks. That sounds like pretty much all I need to know at this point!
- alceta 8y agoI can fully second this approach. We migrated away from a plain AngularJS application in 2016. The sheer number of bugs we have since been able to prevent by the (ever improving) strictness checks of Typescript is staggering. And all that, with what I believe is excellent documentation and support. I mean you're getting a getting started comment from the lead managers on the project Thanks Daniel!
- ifightcrime 8y agoWhy did it take you so long! :)
- Waterluvian 8y agoGood question! I wasn't experienced enough to realise its value on projects where it would have been great. And since then I haven't done any projects that it makes sense for: Smaller projects built by a one-person team that value quick experimentation and iteration above all else. Now that my work has shipped and the robots are happily doing their robot things, I can go and harden it all before the team grows significantly next year. TypeScript seems like a perfect tool to help structure a codebase prior to bringing on more developers.