microsoft / microsoft/TypeScript
Feature: Analyze @throws tags
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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
/**
* @throws {SomeException}
*/
function myFunction() {
// some logic
// then for some reason we throw an exception
if (somethingWentWrong) {
throw new SomeException("something happened");
}
// some more logic
}
function potentialMess() {
myFunction(); // Compiler error: 'myFunction' may throw `SomeException`. ts(9876)
}
/**
* @throws {SomeException}
*/
function letItBubble() {
myFunction(); // No compiler errors
}
function aFunctionThatHandlesTheException() {
try {
myFunction(); // No compiler errors
}
catch (error) {
// do something with the error
}
}
Questions
-
Ideally, it would be even better if VSCode realizes that
myFunctionthrows an error, and then@throwsis not required for the analysis. Still, this approach would be useful when dealing with external code/interfaces. -
It is my understanding that JSDoc's
@throwsis 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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the issue's JSDoc @throws examples and trace how the TypeScript compiler handles calls, thrown errors, and try/catch control flow. Define done as warnings or configurable errors for unhandled calls, propagation when the caller declares @throws, and no diagnostic when the exception is caught; the questions about inferred throws and repeated tags require design decisions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100