4 ms·
For someone who writes TS only occasionally and mostly doesn't care about the JS ecosystem, this is a great article. I picked up a few tricks. That said, normal
by rednafi 2y ago
For someone who writes TS only occasionally and mostly doesn't care about the JS ecosystem, this is a great article. I picked up a few tricks. That said, normalization of warts is a common thing in JS, and people tend to just live with it rather than fix it. This feels like another example of that.
In Go, if something is discouraged (unsafe, runtime, reflection shenanigans), you immediately know why. The language is mostly free of things that exist but you shouldn’t use.
TS was a breath of fresh air when it came out. I never took Node seriously for backend work—it was always something I reluctantly touched for client-side stuff. But TS made some of JS’s warts bearable. Over time, though, it’s added so many crufts and features that these days, I shudder at the thought of reading a TS expert’s type sludge.
- baq 2y agoTS type sludge is required to make the JS underneath workable. I'd welcome TS type system in Python, mypy and co. should steal it outright.
- rednafi 2y agoI also work with Python, and I agree that TS has a better type system than Python. However, Python doesn’t require an additional compilation step, which is a win for it. That said, with tools like Bun, Deno, and Node now capable of running TS out of the box, that’s another win for TS.
- benrutter 2y agoI'm a Python developer, and use a bunch of types day-to-day, I haven't used TS aside from intermittent curiousity. Curious what aspects TS has that Python doesn't? (or that Python doesn't do as well)
- baq 2y agoI really like that TS makes it possible to work with raw objects (~dicts) without having to worry about keys existing or not existing, especially narrowing down via Pick<> and tricks related to impossible combinations via the never type are nice (e.g. if it has key 'a', it can't have key 'b' and vice versa). That said Python's typing doesn't sit still and I tuned out a couple of years ago, so all those things might be possible today via TypedDict, haven't checked).
- rednafi 2y agoSpot on. Record types and Pick/Omit in TS is something I miss in Python. It's still not there. TypedDict solves some of the issues but it's a lot more verbose than TS and isn't half as nice.
- rednafi 2y agoI work with both Python and TS. Python's type hints feel bolted onto the language, whereas TS feels more native. In Python, you have to import a whole bunch of stuff for typing, which adds runtime overhead. For example, typing a decorator means importing `ParamSpec`, `Callable`, and a bunch of other things. In TS, all of that is available in the global scope, so it’s way less cluttered. Plus, the type system in TS is a lot more powerful. Generic record types are way nicer in TS than in Python.
- rvz 2y ago> I never took Node seriously for backend work—it was always something I reluctantly touched for client-side stuff That was my initial assessment as well. Anything JavaScript related I stood clear and far away from using it anywhere near backend systems and relegated it into the list of non-serious technologies to stay away from. > Over time, though, it’s added so many crufts and features that these days, I shudder at the thought of reading a TS expert’s type sludge. TypeScript just repeated the same issues as CoffeeScript and both JS and TS are just as bad for software anyways. Go and Kotlin have much better type systems, but the rest of the JS ecosystem just reeks with immaturity.
- rednafi 2y ago> That was my initial assessment as well. Anything JavaScript related I stood clear and far away from using it anywhere near backend systems and relegated it into the list of non-serious technologies to stay away from. Same. The frontend can sustain this continuous churn but the backend can't. I go for Go or Python to build backends these days.