4 ms·
I'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 does
by benrutter 2y ago
I'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.