News for hackers. Stuff that matters.
Re:State of JavaScript 2019 by bryanrasmussen on Thursday December 19, 2019 @07:25AM (#21834262)
I personally dislike Typescript as it is most often a hindrance for me, but:

About 2 years ago I had a pull request from a junior Dev - I can't remember all of it but basically he had an event (passed from some slider component) if something in that event was undefined he set a variable to be null otherwise it was an array, then he did an if check against something else in the event, and inside the if he checked the length of the variable.

So of course I pointed out that getting the length of null would be a problem. I actually had to argue with him a bit because he thought it was necessary for reasons. I got him to go through his code again and stuff was refactored to be better.

Typescript would have solved that problem.

I am in a big react SPA right now, that also uses TypeScript, often TypeScript causes problems of the sort - I am in a place where X could possibly be one or the other type (null or an object) so you need to write a check for it, in reality it would never have gotten to that particular point if it was null but poor TypeScript cannot figure that out.

Often things are wrong because some library thinks something is an Element instead of an HtmlElement or similar type of problem etc. etc. you have to go fix types, which can take more time than it should.

Finally it can be that TypeScript gives you very cryptic messages about what is wrong and it can take a while to decode what is wrong with otherwise fine code.

I can also say that in the 8 months I have been on the project I think TypeScript has caught two bugs I would have been putting in.

This is based on 18 years JavaScript experience 1 year TS experience. So I don't think it offers no benefit, I think it offers some benefit and irritates me more than it benefits me - but that is not the same thing. I must say that if you've been using it for 2 years and never had that oh yeah, I didn't think of that experience - well that's pretty impressive as regards your attention to detail.

on edit: although I have 18 years JS experience I would say only 7 years major usage, full time doing major stuff with it.

Re:State of JavaScript 2019 by 734129837261 on Sunday December 22, 2019 @09:28PM (#21861074)
Well, TS does point things out to me in the IDE that make me correct it right there. But, I would have caught that in my browser in under 2 seconds anyway. With proper .map files to debug things it's infinitely more clear what's wrong than with TS's sometimes very cryptic messages.

As for your junior dev, maybe that makes the case for TS. But honestly, I've experienced junior TS developers who were simply overwhelmed by TS. They couldn't be trusted to write proper TS since they already struggled with JS. It just required us to review more code in their PRs.

I'll take a project with naming conventions, proper unit tests & code reviews over TS any day.