Skip to main content

require-throws-tag

Require @throws tags for documented functions and methods that throw.

Targeted pattern scopeโ€‹

This rule checks documented functions/methods with block bodies and reports when they contain throw statements but no @throws (or @throw) tag.

What this rule reportsโ€‹

This rule reports missing throw documentation when a function body includes throw logic.

Why this rule existsโ€‹

Exception behavior is critical API contract information. Missing @throws tags make error handling expectations unclear in generated docs.

โŒ Incorrectโ€‹

/**
* Parse JSON content.
* @param input JSON source.
* @returns Parsed object.
*/
export function parseJson(input: string): unknown {
if (input.length === 0) {
throw new TypeError("Input must not be empty.");
}

return JSON.parse(input);
}

โœ… Correctโ€‹

/**
* Parse JSON content.
* @param input JSON source.
* @returns Parsed object.
* @throws {TypeError} When the input is empty.
*/
export function parseJson(input: string): unknown {
if (input.length === 0) {
throw new TypeError("Input must not be empty.");
}

return JSON.parse(input);
}

Behavior and migration notesโ€‹

Autofix appends a TODO @throws line. Then replace the placeholder with concrete error semantics.

ESLint flat config exampleโ€‹

import typedocPlugin from "eslint-plugin-typedoc";

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

When not to use itโ€‹

Disable this rule if your team intentionally keeps throw semantics out of TypeDoc prose.

Package documentationโ€‹

TypeDoc package documentation:

Further readingโ€‹

Rule catalog ID: R011

Adoption resourcesโ€‹

  • Enable this in strict rollout stages after baseline doc completeness rules.