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

babel-plugin-jsdoc-type-checker

v3.0.3

Published

Babel plugin for type checking based on JSDoc comments in selected environments.

Readme

babel-plugin-jsdoc-type-checker

Babel plugin that generates a type checking code based on JSDoc comments in supported environments (configurable by supportedEnvironments option).

Example

This ES6 code:

/**
 * Class Foo.
 */
class Foo {
  /**
   * Returns the sum of x, y (optional).
   *
   * @typechecked
   * @param {number} x The first number.
   * @param {number} [y=0] The second number.
   * @return {number} The sum of x and y.
   */
  sum(x, y = 0) {
    return x + y;
  }
}

Will be transformed to:

/**
 * Class Foo.
 */
class Foo {
  /**
   * Returns the sum of x, y (optional).
   *
   * @typechecked
   * @param {number} x The first number.
   * @param {number} [y=0] The second number.
   * @return {number} The sum of x and y.
   */
  sum(x, y = 0) {
    if (typeof x !== 'number') {
      throw new TypeError('Foo.sum(x, [y]): Argument x expected to be a number.');
    }
		
    if (y !== null && y !== undefined && typeof y !== 'number') {
      throw new TypeError('Foo.sum(x, [y]): Argument [y] expected to be a number.');
    }

    return x + y;
  }
}

It transforms only ES6 class methods that have JSDoc comment blocks with @typechecked tag (configurable by checkerTag option) or are members of a class with a JSDoc comment block containing @typechecked tag.

The generated code is configurable by checkingTemplate option. A custom generated code can look like this:

/**
 * Class Foo.
 */
class Foo {
  /**
   * Returns the sum of x, y (optional).
   *
   * @typechecked
   * @param {number} x The first number.
   * @param {number} [y=0] The second number.
   * @return {number} The sum of x and y.
   */
  sum(x, y = 0) {
    invariant(!(typeof x !== 'number'), 'Foo.sum(x, [y]): Argument x expected to be a number.');
    invariant(!(y !== null && y !== undefined && typeof y !== 'number'), 'Foo.sum(x, [y]): Argument [y] expected to be a number.');
    return x + y;
  }
}

This generated code contains Facebook's invariant. You could generate a code that like this, if you set checkingTemplate option to `invariant(!(\${condition}), '\${className}.\${methodName}(\${paramsList}): Argument \${paramName} expected to be \${expectedType}.');`.

It also supports @typedef tags.

Installation

npm install babel-plugin-jsdoc-type-checker --save-dev

Usage

CLI

$ browserify script.js -o bundle.js -t [ babelify --plugins [ babel-plugin-jsdoc-type-checker ] ]

Node

var fs = require('fs');
var browserify = require('browserify');
browserify('./script.js')
  .transform('babelify', { plugins: ['babel-plugin-jsdoc-type-checker'] })
  .bundle()
  .pipe(fs.createWriteStream('bundle.js'));

Options

checkerTag

string, defaults to 'typechecked'

The plugin generates a type checking code only in class methods with a JSDoc comment block that contain a tag that equals to this option's value.

checkingTemplate

string, defaults to `if (\${condition}) { throw new TypeError('\${className}.\${methodName}(\${paramsList}): Argument \${paramName} expected to be \${expectedType}.'); }`

This option determinates how the generated code looks like. Its value is an ES6 template string with some escaped placeholders:

  • \${className} is a name of the class, in which we are checking the type,
  • \${condition} is a placeholder for a generated condition,
  • \${expectedType} is an expected type of the parameter, that is being checked,
  • \${methodName} is a name of the method, in which we are checking the type,
  • \${paramName} is a name of the parameter, that is being checked (a name of the parameter is enclosed into square brackets [], if the parameter is optional)
  • \${paramList} is a list of the method's parameters,

importTemplate

string, defaults to ''

The plugin generates an import statement automatically if you set this option, but only if an identical import statement is not present in the code. Example value: `import invariant from 'invariant';`

supportedEnvironments

string[], defaults to ['dev', 'development', 'test']

An array of environments in which the plugin generates a type checking code. If process.env.NODE_ENV equals to some of these items, the plugin will generate the code.