-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Analyze @throws tags #31329
Comments
This is likely out of scope. TypeScript powers the VS Code JavaScript IntelliSense and it does not have support for java typed exceptions like this describes. I also do not think this it is on the roadmap |
Thanks @mjbvz for the response. Given that other common JSDoc tags such as Update: actually, when it comes to parsing JSDoc, on second thought I believe this suggestion should be done to the VS Code project, sorry. Still, would be nice to see TypeScript support for typed errors, but this is not what this issue describes. Thank you! |
I second this. Having support for The syntax could be something along the lines of function dooSomething(): void | throws {
} |
Not sure @ahejlsberg has changed his stance on checked exceptions:
I personally agree with this, I have seen a lot of bad code written as a result of people being forced to handle exceptions they have no idea what to do with (ending up in exceptions being eaten without a trace and the app not working) @AlCalzone not sure just |
+1 Let me show you some code, which shows the real case.
So, seems very useful to have
In the case, if you are using 3rd party functions in your own implementation with their own throws, you can also write typedef import for this specific error and write extra throws JSDoc for your function. |
I sure see @ahejlsberg's point, but at the same time I believe it would be a very useful feature even in the example he puts, since especially when dealing with new APIs you may not know what kind of exceptions (or when) this API can throw. This could be implemented as another strict rule that you can opt-in, so everybody's happy. |
I can understand the argument against not using throws in JSDoc only because of dynamic nature. For example
But, if I will highlight Example
I know about
|
For what it's worth, I'd very much like some sort of indicator that a function can throw. I just tried extracting out a common "unexpected state" throw, and realized that I can't do so safely because TS lacks this functionality. |
A potential compromise is for JS, that |
For those that are looking for compile-time error safety in typescript you can use my ts-results library. |
This will need #13219 to be implemented first. |
Description
Given a function has a
@throws
JSDoc tag, it would be helpful to apply some analysis and raise a compiler warning (or, if configured, an error) when the caller does not handle the error and it doesn't declare its own@throws
tag.Examples
Questions
Ideally, it would be even better if VSCode realizes that
myFunction
throws an error, and then@throws
is not required for the analysis. Still, this approach would be useful when dealing with external code/interfaces.It is my understanding that JSDoc's
@throws
is allowed once -- if this is correct, then VSCode could ignore this and accept multiple tags anyway? Otherwise, maybe we can use a different tag, e.g.@exception
?The text was updated successfully, but these errors were encountered: