Live data from Hacker News

Ask HN: Is TypeScript worth it?

news.ycombinator.com

131–140 of 469 posts

Re: Ask HN: Is TypeScript worth it?

#131

I've seen the codebases created and maintained by people who "don't need types because it just slows me down." Hard pass.

Many of the most pleasant codebases I have worked with were built before TypeScript existed. Building a good codebase takes a lot of care and thought and can't come just from using TypeScript, in fact the worst cases I can remember happen to be TypeScript.

By no means am I saying TypeScript is the reason these codebases were poor, however it also didn't seem to help them all that much.

Re: Ask HN: Is TypeScript worth it?

#132
post #128
post #120

Earlier quoted context omitted.

Regarding #1: this is not true always. Libraries publish types and their type definitions could use new TypeScript features that could force an update.

This is rare (I have never run into it in many years of writing TS code and pulling repos from NPM), and if it does happen you can always ignore the definition and turn it back into a plain JS package.

Not rare. Happens every 12 months or so in my experience as a library maintainer. It really sucks that Typescript, let alone .d.ts files produced by the compiler, don’t follow anything resembling semver.

Re: Ask HN: Is TypeScript worth it?

#133
post #114

#1 – You don't have to upgrade TypeScript versions till you are ready, and newer versions never have breaking changes anyways. The syntax remains strictly compatible with ES6 and beyond. Packages you consume publish compiled JS and aren't dependent on specific TypeScript versions at all. #2 – If libraries haven't published types, just use them as pure JavaScript (which is what you would have done anyways). Lack of do…

Just to add to #4, I've worked on some large codebases where transpilation starts taking a very long time, and I begin to think "wow, this is really straining TSC"... so far, every time it's happened, it's been because some sort of data files weren't being excluded from the build.

Idk if I’m just an idiot but my company’s codebase for the last year has had pretty slow tsc compile times and nobody on my team has been able to make it better. Probably since we have a decent amount of generated code that pushes the amount of source code up considerably, but still no good answers to make that better.

Re: Ask HN: Is TypeScript worth it?

#134
post #10

As humans it is easy to forget the time savings that we don't see. For a project that uses a lot of Type annotations, it is like getting a bunch of unit tests for free or writing a bunch of boilerplate code to validate inputs.

I work on a ruby code base that has extremely good test coverage, something around 20,000 unit tests for a relatively simple app, and it’s still almost impossible to update ruby or rails without breaking something. The thing that broke is always impossible to predict from reading the release notes.

The most infuriating thing is it’s almost always something a typed language would have picked up like a functions parameters changed or things removed.

No amount of unit testing or browser automation is a sufficient replacement to type checking.

Re: Ask HN: Is TypeScript worth it?

#135

I'm old enough to have worked on two different large enterprise applications which predated TypeScript and it was a nightmare. Personally I've found that JavaScript lends better to a functional style of coding but there are no protections in the language to enforce this and both codebases I saw had a weird mismatched set of object oriented and functional style principals. Defined classes, prototypical inheritance, mo…

I worked many years before TS too and happened to have been working on very neat codebases back then, though I did have the luck of working with a really talented set of people.

I conceed that perhaps you are correct about this - it does force people to write less strange code. JS gives you so much freedom that if you don't keep it simple you can really hang yourself. However if you put care into your code and keep it simple, I don't think TS helps all that much.

There have also been situations where I have had to do something a little bit strange, and TypeScript made it an absolute mess. And if you do enough JS you'll know that sometimes you do need to write a function that needs to leverage dynamic typing pretty hard, even if it's quite rare.

Re: Ask HN: Is TypeScript worth it?

#137
i) Never had a problem with this, although I use very very few libraries, so that might be why. (At this point basically only preact)

ii) Yes, but this can't be used to favor JS instead. If a library is badly documented, you're going to have a hard time whether using TS or JS.

iii) This is true, but it depends on what you are doing. One advice is to avoid defining complex types. Another good measure is to sometimes suppress type checking on a few lines that you know are correct but are near impossible for the compiler to verify.

iv) I use esbuild to compile, and have a tsc -watch window open all the time.

Re: Ask HN: Is TypeScript worth it?

#138
post #30

The question of whether it's "worth it" really boils down to you and your specific requirements. Even within the same project, there are times when I don't want typechecking - when I am prototyping something out and want to move fast. And there are other times, when I want typechecking - when I am finalizing a feature implementation or doing integration with existing logic etc. It's not a framework. It definitely is…

I have seen this IC vs team aspect discussion before, and it definitely has merit. However I am starting to question if it's even worth it for larger codebases used by many devs, which is why I wanted to pose this question. Can you think of cases where it's actually prevented a bug where that piece of code is unit tested? I have been actively monitoring for this to happen, but so far not seen it (I think I have seen…

Types let you limit the size of the input space - JS lets you go ahead with (foo, bar) where they could be literally anything and you have to handle every edge case to test that (and I bet if you fuzz you'd find stuff) your unit tests don't handle. With a typed language I can specify the input space and know with certainty anything that calls that function (and compiles) is going to be within that space. This lets you dramatically reduce the complexity of your app, tests, and stress of refactoring!

Fwiw I'm an SDET and I regularly find bugs, on a daily basis, in a startup of around 40 people with a Python/JS web stack that TypeScript would have caught (and am pushing towards moving over to it).

Re: Ask HN: Is TypeScript worth it?

#139

As i said before, a lot of people expect that writing typescript is as easy as writing js, which is not. I estimate the typescript tax to be around 40-100% more time, especially if you want to do typescript right and not use `any` all over the place. And besides, typescript is a poor fit for someone who is used to writing highly dynamic, lambda based code, which is one of the main niceities of js. My guess is that a…

These estimations are pure imagination. I doubt you have `any` real data to support it. Also, that is not the reason why Typescript was created, nor the reason why people adopt it, not even what Typescript really is. Today, almost every Node.js framework supports Typescript out of the box. I challenge you to provide a modern framework that doesn't provide types. And this is not an opinion, nor it is wishful thinking,…

I work with typescript everyday. I review prs, i mentor junior devs that are learning typescript. Ofcourse this is my experience, maybe yours is different, if so please tell me about it. The only thing i said is that there is an upfront cost in velocity that people are usually not considering when they are choosing to use ts over js. Sure, that cost may be amortised in fewer bugs and easier collaboration across large development teams. But i see people struggling everyday with specifying correct and complete types. I reject prs, i babysit devs that can't figure out how to type certain code constructs. And if i don't do this the project ends up a mess of anys and ts-ignores which undermines the value proposition of typescript.

Re: Ask HN: Is TypeScript worth it?

#140
post #82
post #71

Earlier quoted context omitted.

I haven't found much agreement, or at least to the extent I believe it, that Javascript and HTML and CSS have all been shoehorned and built upon completely beyond their original specs.

Those sound like the least controversial opinions ever. What's nice is that despite looking ugly, those shoe horns have done a pretty good job, and they all make effective tools for building useful stuff, and that stuff can be built by people who aren't very good at building stuff. It's very much a success story that so much html/css/JavaScript is a garbage fire. They're really effective tools, up there with excel

[deleted]
Post reply on HN