Live data from Hacker News

Ask HN: Is TypeScript worth it?

news.ycombinator.com

201–210 of 469 posts

Re: Ask HN: Is TypeScript worth it?

#201

Are tests useful? Because this is what TypeScript gives you: it helps you avoid regressions. If I change a signature, tests fail. If I pass junk data, tests fail. It's like invisible live tests and people forget this. As in the other recent discussion, yeah, you can live without tests and you can live in JS-land. Whether it's worth it it depends on you. TS and traditional testing lets me ship updates without even ope…

Tests are great and the usual argument from static typing opponents is that they almost completely replace the regression safety from static typing.

Types are not the same as tests at all, tests are much better at giving you a glimpse of what the code even does.

For clarity, I'll define a static typing opponent as somebody who believes that the return on investment for static typing is negative.

Re: Ask HN: Is TypeScript worth it?

#202

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 converted a few codebases from JS to TS and this takes a surprising amount of time. I won't put out estimates but it's definitely non trivial.

> I challenge you to provide a modern framework that doesn't provide types

Ruby on Rails

Re: Ask HN: Is TypeScript worth it?

#203

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…

Great of you to hop in. Just want to say that while I can typically navigate error messages in TS, I do occasionally have to do some googling on some error messages (specifically ones around generics that have a super type that apparently doesn’t necessarily agree with a subtype or something — still don’t quite get it), and it’s nice to see that the TS team recognizes the obtuseness of these messages is an issue.

TS#### error messages was a brilliant idea to make them more ~googleable~ bingable at least.

Re: Ask HN: Is TypeScript worth it?

#204
post #23

> I want to skip over the static typing benefits argument, because I think it is well understood that static typing is a good thing and if we could bless JavaScript with a built-in and robust typing system then I don't think many people would be against that. My issue is with the amount of extra work it places on developers, much of it the "dumb" kind of work which can eat up hours and doesn't deliver all that much v…

Doesn't your counter-argument beg the question whether it is indeed 20% BS vs. 80% value? I think the OP is asking about pretty much that percentage. Personally I feel it's more like 70% BS vs. 30% value. Types, after all, are a very weak ontology, i.e., you still cannot know for sure that just because your code compiles it interprets the values it's getting from other party's code correctly. I would even argue that…

I like TS for the completions and the documentation. I know OP was complaining lack of documentation but knowing what properties a giant object takes, even if those props don't have doc-comments, is still wonderful.

What I've been doing is, whenever I'm handed a random JSON blob, I throw it into a JSON->TS interface converter, paste that back into my project, and I never have to question what the heck the server is returning to me again.

Re: Ask HN: Is TypeScript worth it?

#205
I like it. I wasn't convinced it was worth it for the first year or two, especially when TS was young, but the devs have done a great job and have paved over a lot of the weak spots. Things I didn't even expect would get fixed have been fixed.

I just try to type things 90% of the way, until it's good enough, and slap an `as` in there if I get too annoyed or it takes too long to fix. Don't even care. It doesn't put me in a worse spot than JS would have.

Getting completions on all my giant objects is wonderful.

Re: Ask HN: Is TypeScript worth it?

#206
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[] : number;
  type RemovePrefixDots = Key extends `...${infer Name}` ? Name : Key;
  type Params = {
    [Key in FilteredParts as RemovePrefixDots]: ParamValue;
  };
  type CallbackFn = (req: { params: Params }) => void;
  
  function get(path: Path, callback: CallbackFn) {
    // TODO: implement
  }

  get(
    '/purchase/[shopid]/[itemid]/args/[...args]', 
    ({ params }) => {
      params.shopid // number
      params.itemid // number
      params.args // string[]
    },
  );
(https://lihautan.com/extract-parameters-type-from-string-lit...)

then you probably don't need TypeScript, or types in general. And that is fine.

As to the points:

(i) 99.99% of everything is being developed by someone else in our current stack, but here comes the benefits of open source: don't like how a project is going? fork it and maintain it yourself;

(ii) If you don't use a NPM package with the last release older than 2014 (and why would you given your (i)st fear), chances are pretty high (95%+) the library is written directly in TypeScript or there is a DefinitelyTyped package with the types;

(iii) Type errors, those that come directly from TypeScript, are pretty straightforward (was expecting X, you passed Y);

(iv) Yes, TypeScript should have never been written in an interpreted language, but what were the options in 2012: C? C++? Maybe some day in the unspecified future, we will have a Rust/compiled language implementation with microsecond transpilation time.

Re: Ask HN: Is TypeScript worth it?

#207
Personally I moved over to Rust for as much as I can.

I still use TS on frontend (as frontend framework in rust are not quite there yet when compared to something like solid start - perseus is getting there though) but I definitely use any freely when I'm in a hurry.

That's exactly what I don't like about TS: it enables developer to bypass safety making the whole thing not very safe. You can't trust your dependencies as you normally do with Rust (unless your dependencies specifically opt out with unsafe - there is still deps vetting needed, but it really hasn't been a problem).

Is it worth it? Before swc I would say no, with swc (typescript compiler written in Rust) the perf hit and DX is not too bad and I'd say yes.

Re: Ask HN: Is TypeScript worth it?

#208
post #120
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…

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

That shouldn't happen https://github.com/DefinitelyTyped/DefinitelyTyped#i-want-to...

Re: Ask HN: Is TypeScript worth it?

#209

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…

Thanks for your work, TS saves me time every day. I was saying something similar to the op 3-4 years ago but really cannot picture working without some kind of type safety in JS now.

> TS saves me time every day.

Hmm, not my experience. I do TS for years now and still today I'm spending more time on fighting/pleasing TS compared to the actual code.

JS with all its node_modules dependencies is a complete nightmare to get the typing right. I regularly have to change good solid code to please TS, but at the same time TS often doesn't complain when the typing is obviously wrong.

I once started with Assembly, Pascal, C and C++. So please don't start to explain to me what strict typing is and the benefits and so on, I know. JS uses dynamic typing by design. And I remember how awesome it felt when JS came out and we could write code without doing type juggling. And I believe that with type inference and some other tooling in the IDE we really don't need TS at all.

Re: Ask HN: Is TypeScript worth it?

#210
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"
Post reply on HN