npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

eslint-plugin-explicit-exceptions

v0.13.3

Published

ESLint rules for explicitly handling exceptions

Readme

eslint-plugin-explicit-exceptions

NPM Version Coverage Test

https://github.com/user-attachments/assets/4a833442-b8a5-462f-abeb-a28bd0e5863f

Just as Java’s throws keyword does, enforcing the use of JSDoc’s @throws tag to explicitly specify which exceptions a function can throw to solve unpredictable propagation of exceptions happening which also known as a JavaScript's "hidden exceptions".

Features

  • Reports and provides fixes for throwable functions that are not annotated with @throws.
  • Reports and provides fixes for async functions and Promise rejections.
  • Verifies that the exception types match the documented types.

Examples

For functions that propagate exceptions to the caller because they didn’t handle exceptions, this plugin enforces the use of a @throws comment.

// ❌ Error - no `@throws` tag
function foo() {
  throw new RangeError();
}

// ✅ OK - no exception propagation
function bar() {
  try {
    throw new TypeError();
  } catch {}
}

// ❌ Error
function baz() {
  maybeThrow();
}

// ✅ OK
/** @throws {Error} */
function qux() {
  maybeThrow();
}

It also leverages these comments for type checking, helping ensure that errors are handled safely.

// ❌ Error - type mismatch
/** @throws {TypeError} */
function foo() {
  throw new RangeError();
}

// ✅ OK
/**
 * @throws {TypeError}
 * @throws {RangeError}
 */
function bar() {
  maybeThrowTypeError();
  maybeThrowRangeError();
}

// ✅ OK
/** @throws {number} */
function baz() {
  throw 42;
}

// ✅ OK
/**
 * @throws {"error"}
 */
function qux() {
  throw 'error';
}

For error classes, since TypeScript uses duck typing for type checking, this plugin treats inherited error classes as different types. However, documenting a common parent class is permitted.

// ✅ OK
/** @throws {RangeError | TypeError} */
function foo() {
  maybeThrowRangeError();
  maybeThrowTypeError();
}

// ✅ OK
/** @throws {Error} */
function bar() {
  maybeThrowRangeError();
  maybeThrowTypeError();
}

To clearly distinguish between a synchronous throw and an asynchronous promise rejection, this plugin requires that promise rejections be documented in the special form of Promise<Error>.

/**
 * @throws {Promise<Error>}
 */
function foo() {
  return new Promise((resolve, reject) => reject(new Error()));
}

/**
 * @throws {Promise<TypeError | RangeError>}
 */
async function bar() {
  if (randomBool()) {
    throw new TypeError();  // This becomes promise rejection
  } else {
    return maybeThrowRangeError();
  }
}

For more examples, check out examples directory and rules below.

Rules

Usage

Install dependencies

# https://typescript-eslint.io/getting-started/#step-1-installation
npm install --save-dev eslint @eslint/js typescript typescript-eslint

Install plugin

npm install --save-dev eslint-plugin-explicit-exceptions

[!WARNING]

These packages are experimental.

Install custom types for better built-in, libraries lint support.

# For @types/*, i.e. @types/node
npm install --save-dev @types-with-exceptions/node
# For built-in lib replacement
npm install --save-dev @types-with-exceptions/lib

tsconfig.json

 {
    // ...
+   "typeRoots": [
+     "node_modules/@types",
+     "node_modules/@types-with-exceptions"
+   ],
+   "libReplacement": true,
    // ...
 }

Visit https://github.com/Xvezda/types-with-exceptions to see more.

[!NOTE] I'm working on documentation for frequently used APIs.
https://github.com/Xvezda/types-with-exceptions
However, it's still not usable. As a temporary workaround, you can extend the type interfaces in your own type definitions.

// e.g. Promise.reject()
interface PromiseConstructor {
  /**
   * @throws {Promise<unknown>}
   */
  reject(reason?: any): Promise<unknown>;
}

Create eslint.config.mjs

// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import explicitExceptionsLint from 'eslint-plugin-explicit-exceptions';

export default tseslint.config(
  eslint.configs.recommended,
  tseslint.configs.recommended,
  explicitExceptionsLint.configs.recommendedTypeChecked,
  {
    languageOptions: {
      parserOptions: {
        projectService: true,
        tsconfigRootDir: import.meta.dirname,
      },
    },
  },
);

For legacy, .eslintrc.json

{
  "extends": [
    "eslint:recommended",
    "plugin:eslint-plugin-explicit-exceptions/recommended-type-checked-legacy"
  ],
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "parserOptions": {
    "projectService": true
  },
  "root": true
}

This project uses TypeScript and typescript-eslint to leverage type information. To prevent errors or bugs caused by incorrect type data, it is recommended to set the tsconfig.json "strict" option to true.

Check out typescript-eslint for more information if you having an issue with configuring.

License

MIT License