why should we use "never" when we can use void while throwing Error?
I’m learning TypeScript and I noticed that when a function always throws an error, we can define its return type as never: function throwError(message: string): never { throw new Error(message); } However, this also works: function throwError(message: string): void { throw new Error(message); } Since both implementations throw an error and never return normally, I’m confused about why never is recommended over void in such cases. My understanding so far: void means the function does not return a value. never means the function never completes normally (e.g., throws or runs infinitely). Questio
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.