-
Notifications
You must be signed in to change notification settings - Fork 134
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
RFC: @throws tag for documenting exceptions #171
Comments
(BTW this came up earlier in #63 (comment). In that discussion, I was proposing that |
Whenever TSDoc refers to a type, it needs to be a rigorous syntax that is able to express any possible API type. JSDoc uses something called name paths for this. Since JavaScript types are simple, their syntax is relatively simple. The TSDoc equivalent is called declaration references. It's fairly different because TypeScript's type system is much more challenging to model. We need to distinguish stuff like function overloads, merged declarations, etc. We also support some weird stuff like ECMAScript symbols and quoted identifiers. In TSDoc, your proposed format /**
* @throws core-library#MyError - my description
*/
export function doSomething(): void; But is the type We could solve it by using /**
* @throws {core-library#MyError} a description of when it happens
*/
export function doSomething(): void; But what if the NPM package is called @microsoft/core-library? Now we want to write: /**
* @throws {@microsoft/core-library#MyError} a description of when it happens
*/
export function doSomething(): void; But If I remember right, JSDoc doesn't have this problem because they use a /**
* @throws {module:@microsoft/core-library.MyError} a description of when it happens
*/
export function doSomething(): void; TSDoc chose not to use There's lots of creative ways to resolve ambiguities. The pros/cons tend to be very deep discussions. This case with My main input would be to push our discussion towards a /general/ mechanism that can be used by custom tags as well. A major goal of TSDoc is to be extensible: If users invent custom tags and add them to their docs, this should not prevent other tools from being able to correctly parse the content. (For example, XML is perfectly extensible. Whereas Markdown is not extensible at all -- it's effectively impossible to write content that is portable between implementations.) So I think we could handle this by introducing a general way to embed declaration references in arbitrary content. And then we would say that for @rbuckton who recently put a lot of thought into declaration reference grammar. |
Heh, I suppose a super simple option is like this: /**
* @throws {@link @microsoft/core-library#MyError} a description of when it happens
*/
export function doSomething(): void; |
Are you proposing an informal convention that would be proprietary to your tool? In other words, TSDoc should treat |
I think it makes sense to leave it as a generic text block. That is how it is currently handled in typedoc. Making it special has been requested in TypeStrong/typedoc#1045 but even that wouldn't require any special parsing (just a rendering change). |
I created PR 175 to add support for this tag. |
I think this issue is closed with the merge of #175? |
The RFCs will all get closed when we post the first draft of the spec document. |
Looking at https://tsdoc.org/pages/tags/throws it seems that VSCode today doesn't out of the box currently: Am I missing anything? Seems unsurprising given this issue is still open but want to confirm I'm not missing anything, am I? This spec seems useful, would love to hear if its still planned 5 years since the last comment :) For now, one can easily enough do something none standard like:
|
多个异常应该怎么写 |
In #8 (comment) @bookmoons said:
I've opened this issue so we can have a more focused discussion.
The text was updated successfully, but these errors were encountered: