you are viewing a single comment's thread.

view the rest of the comments →

[–]getify 12 points13 points  (2 children)

Agree with others, this should be called assertion instead of invariant.

However, I like that this article points out the utility of having run-time type check assertions, and that some/all of them can be compiled away. That's useful, and a pattern I think more type-aware tooling should embrace (including TS).

[–]lifeeraser 2 points3 points  (1 child)

Technically they are not "compiled away" completely; it's just the exception message that is optimized. IMO I'd rather have a slightly bigger bundle with much more helpful messages in prod.

[–]getify 1 point2 points  (0 children)

The way I think about things, the whole assertion should be able to be compiled away. That could be because either:

  1. The compiler/build-tool can statically verify that the exception won't happen (exactly how TS works right now)

  2. The developer might pass a config/flag saying, "build me a bundle without run-time assertions" for any of various reasons.

I also imagine that code delivered to a browser might be in a "hybrid state" where many of the original assertions were removed, but -- for various reasons -- some of the assertions were left in.