4 ms·
> I want to challenge this a bit. Your unit test suite should also be able to catch all these things with the right assertions. In general, tests can only find
by wtetzner 6y ago
> I want to challenge this a bit. Your unit test suite should also be able to catch all these things with the right assertions.
In general, tests can only find bugs, not prove the absence of them. Type systems, on the other hand, can prove that certain classes of errors cannot exist in the code. They are complementary, you want both.
That being said, I don't think TypeScript's type system is sound, so it's probably not really giving you that benefit.
- spmurrayzzz 6y agoYou make a good point, that theres an inversion of responsibility here. Type systems can infer correctness, test suites have to prove correctness. I'm not sure this makes the toolchain overhead tradeoff a defacto major win, but its persuasive for sure. Curious if you could elaborate on why you don't think the TS type system is sound? I'm not familiar with any arguments to this end currently.
- striking 6y agoIt is unsound. One of the most impactful unsoundnesses is when you cast one array type to another compatible but not exactly equivalent type, and then write to the array. In Flow (another type system) you simply can't do that without making the array read-only at type level. In TS, they decided to allow this for ease of use purposes. Just in general, the TS team optimizes for a balance of bug catching and usability. It is a compromise. Flow is a much more advanced type checker that works even harder at inferring types and eliminating bugs at the type level. It's very cool! But its community is much smaller, the tooling isn't nearly as good, and it has some major performance issues. My workplace is migrating away from it in favor of TS, which is good enough without being too slow or incompatible with our tools.