by amackera · 5y ago · 0 comments
Coming from a C/C++ background originally, quite frankly I don't see the supposed benefits of static typing, and in fact I'm intimately familiar with how type systems can be abused to terrible effect (on code quality and developer morale). IDE support is great until your IDE is a bloated mess (Jetbrains, Visual Studio, etc.).
I have recently picked up ClojureScript and it's a lot easier to understand than TS and incredibly productive to use in real life. No static typing in sight. Just my own little field report, I don't expect to convince any hard-core TS fans out there to switch. Do what feels right!
I have definitely seen type definitions tortured within an inch of their life, especially in third-party libraries, with multiple layers of generics and utility types and unions until it does take a 9000 IQ to parse them (or worse, figure out why a given data structure is throwing a type error).
While I've come to enjoy the "safety net" and autocompletion of strong types, I've discovered what I really want is meta-programming guard-rails. For instance, while I can define `type Foo = 1 | 2 | 3`, I'd like to be able to do something like `type Foo: number = x => x > 0 && x < 4`, with arbitrary meta-logic that be checked at build time, no differently than preventing coercing a string to a number. The full scope of what I want is probably NP-hard (`1 | 2 | 3` does not actually prevent `foo += 3`!), in addition to the constraints of the JS compile target, but I can dream. :)
Some of the special types are tricky and make my head hurt but most people will just consume them through autocomplete.
The only thing I miss from transitioning our frontend from React to Blazor is the typescript type system which I always thought was a joy.
If you're smart enough for Clojure then you're smart enough for TypeScript. That doesn't mean you have to like it though, but you don't have to hide that distaste behind incendiary exaggerations about TypeScript only being suitable for superhuman geniuses.
The overwhelming evidence is that TS is popular _because_ it is a safer and easy-to-understand alternative to JS.
I'm a solo dev-- TS probably gets a lot more useful when there's a team of people working together. That would justify the barrier of entry, which was too high for me.