TypeScript: Narrow types in catch clauses
Read OriginalThis article explains TypeScript's restriction that catch clause variables can only be typed as 'any' or 'unknown'. It details three reasons: any value can be thrown in JavaScript, there's only one catch clause per try statement, and the broad range of possible exceptions. It then shows the correct way to narrow error types using instanceof, typeof, and custom type guards.
Comments
No comments yet
Be the first to share your thoughts!
Browser Extension
Get instant access to AllDevBlogs from your browser