5 ms·
We've converted most JS projects I work on to TypeScript now, and it is game-changing. Interesting to read how a much larger company did the transition. Main
by Humphrey 5y ago
We've converted most JS projects I work on to TypeScript now, and it is game-changing. Interesting to read how a much larger company did the transition.
Main takeaways from this article that I have also found are:
- Convert your most imported & core code first - it's much easier to convert files which only have TS imports - so start with those, and work out.
- Generating types for API response data has removed so many runtime errors. We generate types from GraphQL schemas.
While learning TypeScript takes time (but not much really), now I am familiar with it, I would code faster in TS than in JS.
- mixmastamyk 5y agoDoes TS happen reduce any of the JS (non-type) craziness as well or is it a superset? I'd like a language with one good way to do things that transpiles into JS. Not sure if that is TS or perhaps Dart?
- Humphrey 5y ago> Does TS happen reduce any of the JS (non-type) craziness as well? What craziness are you referring too?
- pacaro 5y agoI have no idea which craziness they were referring to, but one thing that TS doesn't provide (for probably obvious reasons) that could be considered craziness, is an integer type. You're still stuck with the JS number.
- mixmastamyk 5y agoStuff like "===" and "use strict; for non-baffling behavior." Lots more of these kind of things I don't want to think about. I want fewer broken things to avoid. A subset, not a superset.
- pacaro 5y agoFor sure. Typescript definitely gets you away from the worst of these, the typing mitigates most of the craziness about the two exact issues that you mention. But nonetheless, when the rubber hits the road, it's still JavaScript that is running, so weirdness is definitely still a thing
- Humphrey 5y agoTS does take into account things like === and you can get warnings for using them wrongly. But I'm not certain... I just don't find myself thinking about === and use strict.
- Humphrey 5y ago> one thing that TS doesn't provide ... is an integer type. This! I'd love an integer type, and I think this would be within the scope of TS: Use a JS number when running, but type check it to integer. There is JS bigint though.
- graftak 5y agoTypeScript is a superset of JavaScript indeed. You are encouraged to write code in a way that’s compatible with TypeScript’s type system.
- gherkinnn 5y agoYou will stop running in coercion issues, provided you've typed it all out and don't use the any type. Which to me is the bulk of the craziness. There still isn't a Float type and you can still recreate all the memeable NaN NaN Batman code that never is an issue in the first place.
- tomnipotent 5y ago> We generate types from GraphQL schemas. This also makes it easier to stub out protobuf/thrift later on. It's a win-win on so many levels.
- ecf 5y ago> - Generating types for API response data has removed so many runtime errors. We generate types from GraphQL schemas. This setup with codegen reading from a gql schema and creating typed react components/hooks that can be immediately imported is the most productive frontend experience I’ve ever come across.