Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you need error handling if your code is typesafe?

If you write some TypeScript code that is typesafe and is not using third party libraries, do you still need error handling, just because who knows what may happen?

like image 338
anotherOne Avatar asked Oct 27 '25 08:10

anotherOne


1 Answers

TypeScript helps verify the consistency of the code base itself, but your system (web app or anything else) has interfaces with the external world. When you specify these interfaces in TypeScript, it asserts that the actual interface will comply with its TypeScript description but there is no guarantee at all when the code runs.

Also, TypeScript does not verify the algorithms you are using. As a simple example it won't prevent you from dividing a number by zero. It won't verify that a recursive function has a correct exit condition either, and so on.

As a conclusion, TypeScript helps you raise type-related errors sooner (before even executing your code) but that does not relieve you from doing proper error handling where it's needed.

like image 55
Guerric P Avatar answered Oct 29 '25 22:10

Guerric P



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!