Skip to main content

require-throws-description

Require @throws tags to include a human-readable description.

Targeted pattern scopeโ€‹

This rule checks TypeDoc comments on function-like declarations and signatures that include a @throws (or @throw) tag.

Supported anchors include exported and local arrow functions and function expressions, concrete/abstract/ambient class methods, function-valued class properties, declared functions, and TypeScript method/call/construct signatures.

What this rule reportsโ€‹

This rule reports throws tags that contain no prose description. A balanced nested JSDoc type such as {Error & { code: string }} is still only a type annotation, not explanatory prose.

Why this rule existsโ€‹

Error type names alone are not enough for consumers. API docs should explain when/why errors occur.

โŒ Incorrectโ€‹

/**
* Parse value.
*
* @param input Input value.
*
* @throws {Error & { code: string }}
*/
export function parseValue(input: string): number {
if (input.length === 0) {
throw new TypeError("Input must not be empty.");
}

return Number.parseInt(input, 10);
}

โœ… Correctโ€‹

/**
* Parse value.
*
* @param input Input value.
*
* @throws {Error & { code: string }} When input is empty.
*/
export function parseValue(input: string): number {
if (input.length === 0) {
throw new TypeError("Input must not be empty.");
}

return Number.parseInt(input, 10);
}

Behavior and migration notesโ€‹

No autofix is provided because generated throw descriptions would be guesswork. Each attached documentation comment reports at most once.

ESLint flat config exampleโ€‹

import typedocPlugin from "eslint-plugin-typedoc";

export default [
{
plugins: { typedoc: typedocPlugin },
rules: {
"typedoc/require-throws-description": "error",
},
},
];

When not to use itโ€‹

Disable if your team documents error semantics in separate docs and keeps tags minimal.

Package documentationโ€‹

TypeDoc package documentation:

Further readingโ€‹

Rule catalog ID: R021

Adoption resourcesโ€‹

  • Pair with require-throws-tag to enforce both throw-tag presence and quality.