Live data from Hacker News

Ask HN: Is TypeScript worth it?

news.ycombinator.com

41–50 of 469 posts

Re: Ask HN: Is TypeScript worth it?

#41
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…

Unit tests only trace one path at a time; static types cover huge possibility-spaces at once. But of course there are things they can't reason about, which is why we still test, but each of the two is better for catching different kinds of things. One isn't sufficient to replace the other.

Re: Ask HN: Is TypeScript worth it?

#42
Something that might help is creating typed / untyped boundaries. Wrap a (possibly untyped) library with your own (maybe incomplete) typed wrapper. Then let Typescript check everything up to your particular boundary and ignore everything afterwards.

It's on you to make sure you're not misusing stuff at the boundary, but less hassle to get set up and always something you can clean up later.

Re: Ask HN: Is TypeScript worth it?

#43
post #38

Earlier quoted context omitted.

Did you upgrade Typescript (and if so, why), or did you upgrade some project dependencies, or type definitions? > No documentation of types means going into source code to see what is there. Sometimes there could be multiple types that could be used for something, and it's not clear which should be used. I haven't had this experience, and I'm not super experienced with Typescript. Are you using VS Code? It typically…

> Did you upgrade Typescript (and if so, why), What an odd question! Even ignoring new features and better type inference that comes with new versions — once you add typescript to your project, it becomes one of its dependencies. Don't you regularly update your dependencies, just as a good practice, not to let your codebase slowly rot?

> Don't you regularly update your dependencies

No. Update dependencies as needed for security patches (which typically avoid breaking changes), other than that never update unless there is an explicit business need.

Re: Ask HN: Is TypeScript worth it?

#44

Earlier quoted context omitted.

> No. It's a language compiler. You can upgrade it safely without changing a single line in your codebase. If there is a breaking change (sometimes, regarding the strictness) there's also a configuration option that lets you keep the previous behavior. I am currently stuck on a very difficult issue because of a TypeScript upgrade. The upgrade caused a type mismatch with a dependency that wasn't previously an issue, a…

Did you upgrade Typescript (and if so, why), or did you upgrade some project dependencies, or type definitions? > No documentation of types means going into source code to see what is there. Sometimes there could be multiple types that could be used for something, and it's not clear which should be used. I haven't had this experience, and I'm not super experienced with Typescript. Are you using VS Code? It typically…

> Did you upgrade Typescript (and if so, why), or did you upgrade some project dependencies, or type definitions?

I need to upgrade it because I upgraded a dependency that needed a newer version of TypeScript to compile! And I needed that dependency to be upgraded to use a newer version of NodeJS.

It seems that the newer version of TS was more strict, and now I can't find a type from ProtobufJS that fits the code. I can update here when I understand more about this particular case, but presently my best bet is to loose some typing and autocompleting by using some unknown types :(

Re: Ask HN: Is TypeScript worth it?

#45
As for "worth it" — as someone replied in another comment, it's a question for you. You better than us know your use case, your strengths and weaknesses.

Me, I love typescript. It's an extra reassurance that my code will probably work correctly — and even though it isn't as trustworthy as Elm, Haskell, or Purescript, it's better than nothing. It is a good pair programmer who has many times saved me from stupid mistakes I made while writing code. And it holds my hand while I am refactoring — I would be scared to do that in a javascript codebase. Tests would help with refactoring, of course; but they aren't as exhaustive as a static type checker is.

Re: Ask HN: Is TypeScript worth it?

#46

i) TS isn't a framework. And you don't have to use it everywhere in your system. You can decide how heavily to leverage it, developing a 'core' TS subset that powers a broader JS layer (or the opposite, or something different) ii) Lots of libraries are extremely well documented and typed. This is the same in any language not just for types but also for docs, capability, perf etc. This argument applies to all software…

> ii) Lots of libraries are extremely well documented and typed. This is the same in any language not just for types but also for docs, capability, perf etc. This argument applies to all software everywhere so it doesn't make sense to single out TS I am singling out TS because although most good libraries have documentation for all of their methods, along with examples, many useful and popular libraries do not includ…

> many useful and popular libraries do not include full documentation of their types

> but many authors choose to show their examples in JS, in order not to be too opinionated

This is certainly true sometimes, but I don't see why it's a reason against using TypeScript? If you're calling a TypeScript API, the way you use it should look basically the same as the way you'd use it in JavaScript. You usually don't have to do anything special with the library's types unless you're getting fancy

There are exceptions- I've had a rough time fighting to get code using the styled-components library to fully typecheck, because that library gets super fancy with the way they represent things (I don't like it for that reason personally, but I know others do). But libraries like that are the exception in my experience, and if it's really that big of a drain on productivity, you can always bail out and use `any` types to skip dealing with it

Re: Ask HN: Is TypeScript worth it?

#47

My use case is a bit odd, but I've been using it for small personal web projects — so small that no dependencies are being pulled in and bare tsc is being used in place of a bundler — and as someone who doesn't have all of the ins/outs and do's/don'ts of JavaScript committed to memory (the vast majority of code I write is Swift or Kotlin) it's wonderful to have something catching errors before I save and reload the b…

Same here, I've found it very useful in projects where I don't have a lot of dependencies.

In another project with more exotic dependencies, it has become a hassle somewhat. I've found learning the .d.ts syntax to help easily get out of a situation, but it was a learning curve I still run into sometimes.

Re: Ask HN: Is TypeScript worth it?

#49
post #45

As for "worth it" — as someone replied in another comment, it's a question for you. You better than us know your use case, your strengths and weaknesses. Me, I love typescript. It's an extra reassurance that my code will probably work correctly — and even though it isn't as trustworthy as Elm, Haskell, or Purescript, it's better than nothing. It is a good pair programmer who has many times saved me from stupid mistak…

My question wasn't so much asking whether I should continue to use it, that depends largely on what people have already decided to use on a codebase, or what a team or company has decided to do.

I pose this question more so to understand how others are thinking about TypeScript, and whether there is sentiment out there like mine that the tradeoffs are not really worth it in any case, regardless of what is being built.

Re: Ask HN: Is TypeScript worth it?

#50
Yep. I've had the foolish (mis?)fortune of scaling a couple of frontend projects from small to not-so-small starting in JavaScript and then converting to TypeScript. In each one, starting out with vanilla JavaScript was faster (no build!), but at some point our velocity would slow as changes required more testing infrastructure. After switching to TypeScript, we were faster than before.

Sure, dealing with TypeScript can be a hassle, but it is less hassle than dealing with broken software.

Post reply on HN