Hacker News new | ask | show | jobs
by pontilanda 1259 days ago
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 opening node or the browser.

2 comments

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.

> tests are much better at giving you a glimpse of what the code even does

Types do that, they tell you the expected input and expected output. No type nor test is all-encompassing of course, but it gives at least some information.

No test will guarantee that a function will never return a number. Types, if valid and without prototypal shenanigans, can.

While I agree that static typing provides some of the benefits of unit tests, I think it provides much more than that: compiler-assisted renames, code completion, extra code documentation...