News for hackers. Stuff that matters.
Re:First look: adding type annotations to JavaScript by Turing_Machine on Thursday March 10, 2022 @09:55AM (#30627580)
I've often speculated that strong typing only seems like a win to the kind of developer who makes a lot of type errors, and a waste of time to those who don't (which doesn't mean they don't make other errors, of course).
Re:First look: adding type annotations to JavaScript by david422 on Thursday March 10, 2022 @11:06AM (#30628450)
> like a win to the kind of developer who makes a lot of type errors

Or just to the developer that likes to offload that cognitive load to their tools.

Why hold that in my head when the IDE can keep track of it for me? Why memorize every single attribute name when the IDE can autocomplete it for me? etc.

Re:First look: adding type annotations to JavaScript by Turing_Machine on Friday March 11, 2022 @04:09PM (#30646050)
This is about manually-written type annotations. About as far as can be from "the IDE keeping track of it for you".
Re:First look: adding type annotations to JavaScript by david422 on Wednesday March 16, 2022 @11:37AM (#30700120)
You manually write the type annotation, and then the IDE keeps track of the rest.

Instead keeping track of the type annotation in your head, and then also keeping track of the rest of the stuff in your head too.

Re:First look: adding type annotations to JavaScript by markstos on Thursday March 10, 2022 @10:09AM (#30627726)
Even developers who "don't make type errors" have to deal with bad and unexpected data, which may be in a different type.

If you don't validate that all untrusted data is off the appropriate type, security vulns or "garbage in - garbage out" bugs can result.

Then if you do manually validate the types of untrusted data, then you have to wonder of having built-in type support might be faster.

"Bad data" doesn't just come from the outside world. As teams start to use shared libraries written by other people, it's also valuable adds guards to ensure that shared functions are being called with the expected types.

My own experience is that it doesn't feel like type-related bugs come up often on my team, but when they do the problems they cause can be bad enough to make us wish more of our code had been ported to TypeScript.

Classic example: a CSV parser parsed numbers as strings because a particular spreadsheet quoted the number column. Result: "2"+"2" = "22"

Re:First look: adding type annotations to JavaScript by jeremyjh on Thursday March 10, 2022 @11:07AM (#30628465)
I’ve speculated that a lot of developers don’t recognize type errors for what they are.
Re:First look: adding type annotations to JavaScript by rattlesnakedave on Thursday March 10, 2022 @10:09AM (#30627733)
bringing in tooling to eliminate an entire class of potential errors sounds sounds like an easy decision to me.
Re:First look: adding type annotations to JavaScript by Turing_Machine on Thursday March 10, 2022 @10:34AM (#30628039)
Not if the errors are rare and the "tooling" slows down development.
Re:First look: adding type annotations to JavaScript by moron4hire on Thursday March 10, 2022 @11:18AM (#30628617)
Huh? Rebundling my 150kloc project takes about 2 seconds after I save a file and has already reloaded by the time I get to my browser window.
Re:First look: adding type annotations to JavaScript by frosted-flakes on Thursday March 10, 2022 @10:39AM (#30628107)
Why do you think it would slow down development? Serious question.
Re:First look: adding type annotations to JavaScript by Turing_Machine on Thursday March 10, 2022 @01:09PM (#30630254)
Those type annotations don't just magically appear. You have to write them.

Yeah, they're optional, but if you don't write them, there's no point in using TypeScript in the first place.

Re:First look: adding type annotations to JavaScript by jeremyjh on Thursday March 10, 2022 @01:15PM (#30630332)
Types are inferred even when you don't specify them; if you are using a library that has type specifications a lot of your code is going to be well-typed just as a consequence of using that library.
Re:First look: adding type annotations to JavaScript by Turing_Machine on Friday March 11, 2022 @04:05PM (#30646008)
1) "Someone else wrote them" doesn't make them free. Given a limited amount of developer time, that means that the time spent on the annotations wasn't spent on other functionality.

2) If the types can be inferred, that should just happen. No objection there. But this piece is specifically about "adding (manually-authored) type annotations to JavaScript"

Re:First look: adding type annotations to JavaScript by scns on Thursday March 10, 2022 @10:57AM (#30628347)
I was shocked how slow tsc is. Got spoiled by using ReasonML before.
Re:First look: adding type annotations to JavaScript by balefrost on Thursday March 10, 2022 @11:04AM (#30628438)
Alternatively, perhaps advocates of static typing simply see a larger variety of errors as type errors. In JS, if I typo a key of an object (e.g. `foo.excute()` instead of `foo.execute()`), I would call that a type error... or at least an error that could be caught by a static type system.
Re:First look: adding type annotations to JavaScript by Aldo_MX on Thursday March 10, 2022 @10:01AM (#30627641)
Or to the kind of developer that works in a big team for a big project.