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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@conflux-dev/jsdoc-tsimport-plugin

v1.0.5

Published

A JSDoc plugin to support the typescript module import syntax.

Downloads

8

Readme

jsdoc-tsimport-plugin

A JSDoc plugin to support the Typescript import syntax.

NPM Package NPM Downloads

What is it?

A workaround to VSCode and WebStorm not supporting JSDoc typedef imports.

What JSDocs expects:

/**
 * @type {module:path/to/module~MyTypeDefName}
 */

What VSCode expects (as well as Webstorm to a limited degree):

/**
 * @type {typeof import("./path/to/module").MyTypeDefName}
 */

This plugin adds hooks to JSDoc that translates the VSCode supported syntax into the JSDoc supported syntax.

Why?

This allows you to create typedef doclets in a file that can be shared. Just use the typescript-style imports within your doc comments, and then the plugin will translate when you build your jsdocs. This is preferable to adding unused es6/commonjs imports to your code, which may cause unintended side-effects, or fail linting requirements.

How?

To get started, first install this package with: npm install --save-dev jsdoc-tsimport-plugin

Then in your jsdoc.conf.json settings, add the plugin:

"plugins": [
  "node_modules/jsdoc-tsimport-plugin/index.js"
]

Then, write your doc comment typedef import statements in the typescript style.

/// src/model.js

/** @file Model type definitions */
/** @module */

/**
 * An address model.
 *
 * @typedef {object} Address
 *
 * @property {number} houseNumber The house number.
 * @property {string} street The street.
 * @property {string} city The city.
 * @property {string} state The state.
 * @property {number} zip The zip.
 */
/// src/addressView.js

/** @typedef {import('./model.js').Address} Address

If everything is working, when you run jsdoc you should get a linkable definition for your type. Example:

| Name | Type | Description | | ------------- | ------------- | -------------- | | shippingAddress | module:model~Address | The shipping address. |

ESLint

If you're using ESLint, we recommend turning the built-in jsdoc validation off (it's deprecated anyway), and using eslint-plugin-jsdoc. And then set your jsdoc style to 'typescript'.

.eslintrc.json

{
  "extends": [
    "plugin:jsdoc/recommended"
  ],
  "plugins": ["jsdoc"],
  "rules": {
    "valid-jsdoc": "off"
  },
  "settings": {
    "jsdoc": {
      "mode": "typescript"
    }
  }
}

Considerations

This will take into account @module tags, multiple source directories, and complex paths.

For example:

/// src/path/a/model.js

/** @module call/me/ishmael */

/**
 * Another type definition.
 *
 * @typedef {object} MyType
 * @property {number} foo
 */
/// src/path/b/view.js

/**
 * @param {import('../a/model').MyType} data
 */
function show(data) {}

In that example the import('../a/model').MyType will be replaced in jsdoc with module:call/me/ishmael~MyType.

Known Limitations

In Webstorm, the Typescript import syntax is only partially supported. It will not type hint for local files this way. However, the JSDoc module syntax is entirely unsupported and shows error markers, so this is still an improvement.

References

This references the issues:

  • https://github.com/jsdoc/jsdoc/issues/1537
  • https://github.com/jsdoc/jsdoc/issues/1645
  • https://github.com/jsdoc/jsdoc/issues/1632