Remix.run Logo
esafak 4 days ago

It's obviously not a replacement. You can get the types right but the values wrong due to faulty logic.

MrJohz 4 days ago | parent [-]

Sure, but only some of the unit tests are about values. Others, at least in my experience, are any handing various aspects of the implied types of values, and those can largely be removed.

Moreover, a good type system can also force the values to be right by enforcing certain invariants directly in the type system. For example, let's say I have a function `deleteProjectAs(user, project)` that deletes a project, but it only works if the user is an admin, otherwise it throws an error. I can write a bunch of tests that validate that this function checks that the user is an admin in all sorts of different cases, but with a type system I can write something like `deleteProjectAsUser(user: Admin, project: Project)`, and this guarantees at the type level that no non-Admin user can delete a project.

The point here is not that types can replace all tests, but that well-designed types can get rid of a lot of them.

esafak 4 days ago | parent [-]

I agree. My post was unnecessary; I did not realize the response was talking specifically about type bugs.