Typescript is great but be aware that sometimes it can annoyingly slow you down. Consider these scenarios: - You want to use a third party library but it is completely untyped - You need an object but you're just prototyping it. You don't yet know which keys will be optional - You type a key of one of your objects. Now you load or fetch data from an API and want to assign that to it. But typescript complains because…
Ask HN: Is TypeScript worth it?
251–260 of 469 posts
Re: Ask HN: Is TypeScript worth it?
#252Earlier quoted context omitted.
[flagged]
I agree that is not a good example, but the exact same thing can happen in more subtle ways that is hard to catch. For instance you might have a function that returns a user. Do you pass in the user ID argument as a string or a number?
It's actually a great example, because in JS Math.sqrt("4") returns 2 because of JS's idiotic type coercion rules. So if you're passing in user input and don't typecheck it, it will work fine until someone inputs a letter instead of a number.
Re: Ask HN: Is TypeScript worth it?
#253I love TypeScript in the right places, but I think it’s often used for things where other tools would be a much better fit. On the backend it can be nice if you’ve got a monorepo including the front ends it supports. Maybe you’ve got graphql happening and you can share types. That seems great sometimes, and there are cases where it’s super handy and efficient. I don’t know for sure, but it doesn’t seem worth it after…
There are alternatives to NPM, and high performance build tools. A lot of code-quality tools like linting are on the slower side though. Ultimately people use TS on the back end because they want to simplify hiring and reduce context switching loss in developers mostly, and in some cases because their application is isomorphic. This choice works well when the ratio of front end to back end code is high (which is the…
In my experience this hasn’t panned out particularly well, but I believe it works for some teams.
> because their application is isomorphic
This is one case where it had worked out okay for me. The scope has tended to be relatively limited and there was a framework in place which was generally good at gluing things together and ensuring people work along the same rails.
> I wouldn’t write most services in rust…
No, me either. I tend to teach for Go for web services these days, but I do like rust for CLIs and situations where optimizations are crucial. Admittedly I don’t even like Go as a language that much, but it’s great at what it does if I’m willing to put my head down, deal with the quirks and verbosity, and crank something out. It’s not a language of cleverness or elegance, but the results tend to be excellent and easy to maintain.
Re: Ask HN: Is TypeScript worth it?
#254Earlier quoted context omitted.
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.
That being said, it seems like Clang or GCC don't do that at all, which perplexes me a bit. Perhaps it doesn't matter much when error messages are never localized.
Re: Ask HN: Is TypeScript worth it?
#255I'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 th…
Re: Ask HN: Is TypeScript worth it?
#256As 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,…
Re: Ask HN: Is TypeScript worth it?
#257Learn 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[]…
On the other hand, if I open a project and I see many lines of complex types that don't do anything and I have to understand these types to use them to fix some bug, I'm going to say words out loud that I cannot write here.
I've seen projects where there were many lines of complex types and, after updating some dependencies, there were many type errors even though the project ran fine and the tests were all green. Pisses me off every time.
So in the end, I rather just see `params` be `unknown` and create a function to extract typed values, like `getNumberParam(params, 'shopid')` that returns a number or throws some kind of error. That way, you can compile-time checks AND run-time checks.
Re: Ask HN: Is TypeScript worth it?
#258If you have a larger team, yes it is worth it. If it is your side project or if you are like 2 people working on a project then I would say it's probably not worth it.
Typescripts biggest strength is that it's easier to work several people on the same thing. When someone else makes a change, it's easier to figure out what their code does.
The bigger the team and project, the bigger benefits you will get from typescript. At least, that is my opinion.
Re: Ask HN: Is TypeScript worth it?
#259Re: Ask HN: Is TypeScript worth it?
#260As 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,…