Typed error
One less "any" in the codebase.
In our BodyIntercetor
, we have a try/catch and the catch block is as follows:
This works, but the error
has the type any. As we expect an Error here, we can use the instanceof operator on error
, to ensure it's actually an instance of Error.
Subclasses are also included. In this case, error should be a SyntaxError.
We also get type safety in the process. Thanks to Matt Pocock for his insight in this lesson.
Commit - Providing type safety to error
Last updated