Blog Logo

Handling Errors Like a Pro in TypeScript

Error handling in Type/JavaScript is crucial for the longevity of any project. This article discusses how to handle errors cleanly with TypeScript and introduces a design pattern for grouping code by domains in directories called Features. Each Feature directory contains an errors.ts file where a custom error class is defined for the respective domain. By narrowing the error type using instanceof, gives us intellisense and allows us to perform logic based on the name of the error that was thrown. This ensures that errors are caught and logged properly, improving the overall quality of the project.