LearningTypeScript / site

Companion website for the Learning TypeScript book.
https://learningtypescript.com
MIT License
47 stars 11 forks source link

Article: Why throwing errors isn't type-safe #134

Closed JoshuaKGoldberg closed 3 weeks ago

JoshuaKGoldberg commented 6 months ago

Overview

Speaking generally: https://softwareengineering.stackexchange.com/questions/189222/are-exceptions-as-control-flow-considered-a-serious-antipattern-if-so-why is a good summary of my perspective here.

I think the most salient point is the Principle of Least Astonishment. Since exceptions can't reasonably be indicated in type signatures, using exceptions requires developers memorizing which functions may throw them as a part of their "normal" flow. That's a recipe for astonishment - especially if the implicit intentional-exception-throwing contract changes unexpectedly.

JoshuaKGoldberg commented 3 weeks ago

I think #137 -> #138 ended up pretty much answering what this article was looking for. I'll use https://www.learningtypescript.com/articles/why-typescript-doesnt-include-a-throws-keyword#barriers-to-throw-types in its place. 👍