News for hackers. Stuff that matters.
Re:TypeScript 5.0 by i_am_toaster on Thursday March 16, 2023 @03:39PM (#35187213)
I’m always surprised by how much others like typescript. Out of all the languages I have to use, typescript is the one that feels the most like pulling teeth. Maybe I just don’t know how bad it truly was to work with a really large JavaScript project without types and that’s why people love it, but without that experience it just feels like all the hassle of types without most of their benefits.
Re:TypeScript 5.0 by goda90 on Thursday March 16, 2023 @03:42PM (#35187262)
It is truly bad to work with large Javascript projects without types. But I'm curious, what benefits of types do you feel you are missing in Typescript?
Re:TypeScript 5.0 by wnolens on Thursday March 16, 2023 @03:48PM (#35187363)
I feel the same, but when I complain I get blamed. Or someone chimes in with an illegible type/interface definition that solves my issue but is completely out of reach for all but language experts, which in other languages is not an issue.
Re:TypeScript 5.0 by eropple on Thursday March 16, 2023 @07:22PM (#35190367)
Can you provide an example of something you'd see in common use that is 1) not provided by an existing library (such that you are consuming a complex type rather than writing it) and is 2) "out of reach for all but language experts"?
Re:TypeScript 5.0 by madeofpalk on Thursday March 16, 2023 @03:54PM (#35187461)
I'm curious about what languages you're comparing it to. My other experience is with C# and Go, and I find Typescript's type system to be much more expressive and natural to work with.
Re:TypeScript 5.0 by ggregoire on Thursday March 16, 2023 @04:01PM (#35187588)
Your experience probably differs from people who like TS. Personally I don't feel any hassle from using it and I couldn't even start listing all the benefits I get. Even if I know that my new project will have like 3 files and 200 LOC, first thing I'm doing is installing TS.

Not saying it's your case, but I noticed that a lot of people who hate TS like to use techniques and patterns that are usually considered bad practices, which often trigger errors in TS. For examples, mutating an object to add a new property, mutating an array to add an element of a different type, etc.

I also noticed that lot of people who don't like TS think they need to type everything (every variable, every function's return... which is obviously a hassle) instead of relying on types inference. There is usually very little to type in TS (compared to Java or C# for example). The two main things are the parameters of your named functions and your external data (i.e. the fetch responses). Almost everything else can be inferred.

A last category of issues I see with a lot of people who hate TS is related to generics. They do everything they can to avoid using generics and they get very frustrated to not be able to reuse functions with arguments of different types. So instead they hack some workarounds together to avoid TS errors (which makes any future modification or refactoring even worse), usually by first defining the parameter as an union of types and then inserting @ts-ignore everywhere inside the function where TS still shows errors. Or they just copy/paste the function and change the function signature.

Re:TypeScript 5.0 by postdb on Friday March 17, 2023 @02:54AM (#35194078)
>Not saying it's your case, but I noticed that a lot of people who hate TS like to use techniques and patterns that are usually considered bad practices, which often trigger errors in TS. Mutating an object to add a new property, mutating an array to add an element of a different type, processing apples and oranges in the same function without using generics or the correct union type, etc. Code works but TS doesn't like it and forces them to rewrite it properly and it feels like a hassle with no benefits.

Not sure, people who like TS are usually for large corporate projects with OOP background. Most functional lispish type developer would be fine just using ES6 and above.

Re:TypeScript 5.0 by hn_throwaway_99 on Thursday March 16, 2023 @04:07PM (#35187681)
FWIW, when I first started getting into TypeScript from plain JS in 2019, I had a similar feeling. Part of it was that I was dealing with some object types of libraries I was using that were already quite complex. And, given all of the advancements in TS over the past few years, writing new types can be quite difficult - there is just a ton there. E.g. TypeScript's type language is famously turing complete.

That said, I absolutely love TypeScript, even just for small personal projects. The value I get from VSCode typeahead, and being able to look up the expected fields on, for example, parameters or return values of a function is invaluable, never mind its power in refactoring.

I guess I would recommend that, if in the beginning, you feel a bit overwhelmed by TS and can't yet see its value, just give it some time. At least, that's what happened to me.

Re:TypeScript 5.0 by eropple on Thursday March 16, 2023 @04:43PM (#35188261)
I think that TypeScript, properly managed with things like zod or typebox, does an excellent job of giving me those benefits of types that I've come to expect while also having a really, really first-class development experience that reminds me (unsurprisingly?) of how actually-delightful using C# was in its heyday, with ReSharper and Visual Studio making it enjoyable. I genuinely don't feel any hassle around using it; the way that I can start with type signatures and then make the red squiggles go away is a really comfortable way to write code for me.

For me, I was out of the JavaScript cinematic universe for a long time (from about 2011 to 2018) and TypeScript was my entree back in. What got me deeply into it, and has kept me there, is not that it's better than JavaScript, but that, for my purposes, it's better than my at-the-time common languages: Ruby, Java, and C#. It gives me most of the linguistic flexibility that I'm used to with Ruby, while preventing me from dealing with the worst thing about it (Other People's Ruby being high on my list of terrible things). At the same time, it provides a level of "fall into the pit of success" structure around the type system that's superior to Java or C#, while not being as difficult to access as Rust can be.

(I like Rust, too! But the level of experience and skill necessary for somebody to be a "TypeScript operator" remains low, while letting those folks leverage really nice tooling built by folks like me who write TypeScript tools and libraries.)

Re:TypeScript 5.0 by mekster on Thursday March 16, 2023 @04:45PM (#35188293)
I hope your editor supports TS.