Re:Problems with TypeScript
by lucisferre on Wednesday January 15, 2020 @01:18PM
(#22056793)
Tests are the only thing that give me confidence about any code I write, Javascript or otherwise.
[ Parent
| on HN ]
And compilers are effectively a rudimentary form of test. They are not sufficient, nor necessary but they do validate some basic assumptions about the code.
They also remove redundant testing (you only need to prove something fulfills certain properties once as long as you have a type for it); and the more advanced the type system the fewer tests needed.
friendly tips: runtime type checks are available
https://github.com/gcanti/io-ts
https://github.com/pelotom/runtypes
Re:Problems with TypeScript
by paulcowan1970 on Wednesday January 15, 2020 @03:30PM
(#22058139)
I mention io-ts https://github.com/gcanti/io-ts in the post
Thanks for the article
It sparked useful discussion around the world
Re:Problems with TypeScript
by thrower123 on Wednesday January 15, 2020 @09:22PM
(#22061132)
If for no other reason, I would like Typescript for flagging when you typo some property - e.g. foo.FooID vs foo.FooId.
I've lost a stupid amount of time in regular JS because of things like this that make me want to pick up the computer and throw it out the window.
Decent editor does that now. I'm using atom on daily basis and it's helping me with that. VScode and intellij does the same
Re:Problems with TypeScript
by dragonwriter on Wednesday January 15, 2020 @10:41PM
(#22061499)
Doesn't the functionality for that in most editors leverage typescript typings, so that it's not really independent of typescript?
Ah I misread the parent comment. I thought it was more like "I wish typescript has this anti-typo functionality"
You're right that it's not independent from TS.
you can add JSDoc annotations and use a modern IDE like vscode or webstorm, etc.
I would upvote you twice if I can for that compiler is a test thing
Re:Problems with TypeScript
by mirekrusin on Thursday January 16, 2020 @03:30AM
(#22062641)
It's not just about confidence. It's also about the speed you can use/refactor the code. Suggestions, type information on hover and instant feedback if you forgot, used wrong order or type, misspelled or simply don't remember exactly signatures or auto generated documentation means a lot when writing code. You can move much faster when working on typed code. Nobody ever claimed that types are replacement for tests. It just means that your tests don't require obvious clutter anymore, you can focus on more complex/important test cases to cover.
Re:Problems with TypeScript
by Matthias247 on Wednesday January 15, 2020 @02:10PM
(#22057368)
Tests only help if they are written, and if they cover the code in question. Both of things are unfortunately not always given. If things are not covered by tests type systems are still better than nothing.