Live data from Hacker News

Ask HN: Is TypeScript worth it?

news.ycombinator.com

221–230 of 469 posts

Re: Ask HN: Is TypeScript worth it?

#221
In a word: YES.

Update TS regularly to avoid making updates hard and lagging behind to much. Unlike a runtime framework, updates are unlikely to break things at runtime, so there are no reason not to update very often. If some external types are wrong or annoying, don't forget _any_ exists and simply brings you back to the crappy situation you'd have without TS (well admittedly it adds transpilation costs, but it's still type checking everything else, which is well worth it).

I think TS is nearly the best language that could be done given the constraints of being fully compatible with JS.

Re: Ask HN: Is TypeScript worth it?

#222
> i) Like a framework, you are at the whim of TS devs as it gets updated (edited)

I have been using TypeScript for almost 6 years and not experienced this problem. Like everything else keep things simple, don’t chase trends, and so long as do right by your product everything will be smooth. I also don’t waste time with large SPA frameworks.

> ii) Libraries are badly documented

I don’t use many dependencies. The DOM and Node type definitions are extremely well documented and inspired me to write better documentation.

> iii) Error messages are hard to follow

For me this depends on the complexity of a given object or type definition. When things are primitive the error messages are more clear. My only suggestion is to keep your interfaces primitive.

> iv) It requires yet more transpilation

I use SWC as a TypeScript stripper. My nearly 50kloc project takes about 2seconds to covert to JS, which pushes out my total build time to about 2.5seconds.

Re: Ask HN: Is TypeScript worth it?

#223

Learn infer and extends and you will accept all the downsides being zen from the height of your highly well typed codebase. If you don't find the following compelling: type IsParameter = Part extends `[${infer ParamName}]` ? ParamName : never; type FilteredParts = Path extends `${infer PartA}/${infer PartB}` ? IsParameter | FilteredParts : IsParameter ; type ParamValue = Key extends `...${infer Anything}` ? string[]…

Did you write that blog post? Cripes, it is amazing. What a brilliant idea. Thank you to share. My brain is wired for C++ templates, and the technique makes good sense!

To your last point: Why not C#? It is interesting did not mention it, as TypeScript came from Microsoft R&D (as I understand).

Re: Ask HN: Is TypeScript worth it?

#224

I feel like TypeScript is definitely worth it BUT it seems to be getting ever more powerful but not in a good way, in complex way. Too much time is spend fighting TypeScript as opposed to writing application code. I have a question for the language experts out there .... why is TypeScript getting so complex? Are other strongly typed languages this complex? Or does the complexity arise from trying to overlay typing on…

Typescript doesn’t just statically type. That’s easy. It does program flow analysis to 1) infer type and 2) ensure the inferred types actually work. I think in most statically type environments, the type analysis engine relies a lot of on the developer to define the correct types in the correct places, but the types in TS are always _logically_ correct. As in absolutely correct (unless of course you eject from the ty…

> but the types in TS are always _logically_ correct. As in absolutely correct

Erm...

    type Test = Array;

    const xs: Test = [];
    const x = xs[0];
What's the type of x, according to typescript's default behavior? It's number [0]. What's the logically correct type? Some sort of a Maybe, which typescript doesn't have; so a number|undefined instead. Most people don't use typescript at that level of soundness, both because it would be painful, and because typescript doesn't have it as a default.

[0] - https://www.typescriptlang.org/play?#code/C4TwDgpgBAKhDOwoF4...

Re: Ask HN: Is TypeScript worth it?

#225
> static typing is a good thing [...] My issue is with the amount of extra work it places on developers

This is one of the eternal complains about type safety, somehow mitigated by type inference. I believe it is totally worth it in the case of Typescript.

> i) Like a framework, you are at the whim of TS devs as it gets updated (edited)

As a language, it has proven quite stable. Even if development stopped tomorrow you could keep the current version forever.

> ii) Libraries are badly documented

It is inconvenient but, since they are js libraries, they are compatible. You do not need specific ts examples, although it is extra nice.

> iii) Error messages are hard to follow

Did not run into this issue myself but fair enough.

> iv) It requires yet more transpilation

tsc compiles ts into js. Depending on what you use, you could get rid of webpack etc. and just use tsc.

In summary, for me Typescript is totally worth it. All this lost time you mention is different from the lost time adapting to x framework or y packer update, since it reduces errors down the line. It might feel like it is slowing you down, but you can always use any for certain modules and type things at the interface. It is still your decision what to type, the language gives you the tools to do so.

Re: Ask HN: Is TypeScript worth it?

#226

Hi there! I work on the TypeScript team and I respect your feedback. Of course I do think TypeScript is worth it, and I'll try to address some of the points you've raised with my thoughts. i. Dependency management is indeed frustrating. TypeScript doesn't create a new major version for every more-advanced check. In cases where inference might improve or new analyses are added, we run the risk of affecting existing bu…

(A bit )off topic - chatGPT managed to infer your email address based on this comment. Required some hints though - most likely due to my lack of experience (first try). I was curious to see how it can improve indexing in general.

Re: Ask HN: Is TypeScript worth it?

#227
I've been working with JavaScript for 20 years. And 5 years with TypeScript. And, well. I still am not convinced.

Too much overhead for me. I really dislike typing obvious things and boilerplate. Probably my fluency with JS is to blame. I don't need to see types and autocompletion. If I really need to — I just go to the source and inspect the source code, that is how I familiarise myself with the interface. I also think this makes one a better developer.

Re: Ask HN: Is TypeScript worth it?

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

> and newer versions never have breaking changes anyways

Huh? Typescript release note regularly contain information about breaking changes. They may not be dramatic; but they are there.

Re: Ask HN: Is TypeScript worth it?

#229

I don't like JavaScript, I don't like TypeScript, I don't like front end development at all. Is typescript worth it in my personal projects where I know all the code and they are pretty small? In my opinion, no. Is typescript worth it at work, where multiple people interact in a large codebase? Absolutely. Asking if a language is worth it is pointless unless you add "to my use case"

Can't believe how long I had to scroll to find the answer I agree with, effectively: "it depends".

Going with car analogies, the question is similar to "Is a bus better than a race car?" - there's no correct answer without more context. How many people use one or the other, how many people praise one or the other, that's no help either.

That said, regardless of whether it makes me happy or whether it's a solid technical decision, TypeScript appears to be used somewhat widely at this point. So learning to deal with the complexities and gotchas of it is IMHO worth it for anyone who's serious about web development. No need to become a zealot though, there's no need to find and defend some silver bullet. It just depends.

Re: Ask HN: Is TypeScript worth it?

#230
i agree, I have to work with typescript for my current job and I hate every second of it. I was never a fan of any languages that require transpiling. the trade off and trouble it comes with is not worth it for the small benefits. Im not a fan of JS in the first place but typescript just makes it worse.
Post reply on HN