Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jsdoc-plugin-typescript

Package Overview
Dependencies
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsdoc-plugin-typescript

Plugin to make TypeScript's JSDoc type annotations work with JSDoc

  • 3.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.5K
increased by9.19%
Maintainers
3
Weekly downloads
 
Created
Source

jsdoc-plugin-typescript

Plugin to make TypeScript's JSDoc type annotations work with JSDoc. Requires JSDoc v3.6.0 or higher.

Installation and use

JSDoc accepts plugins by simply installing their npm package:

npm install --save-dev jsdoc-plugin-typescript

To configure JSDoc to use the plugin, add the following to the JSDoc configuration file, e.g. conf.json:

"plugins": [
  "jsdoc-plugin-typescript"
],

See http://usejsdoc.org/about-configuring-jsdoc.html for more details on how to configure JSDoc.

What this plugin does

When using the class keyword for defining classes (required by TypeScript), JSDoc requires @classdesc and @extends annotations. With this plugin, no @classdesc and @extends annotations are needed.

Types defined in a project are converted to JSDoc module paths, so they can be documented and linked properly.

In addition to types that are used in the same file that they are defined in, imported types are also supported.

TypeScript and JSDoc use a different syntax for imported types. This plugin converts the TypeScript types so JSDoc can handle them:

Named export

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

To:

/**
 * @type {module:path/to/module.exportName}
 */

Default export

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

To:

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

When assigned to a variable in the exporting module:

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

This syntax is also used when referring to types of @typedefs and @enums.

/**
 * {@link Identifier}
 */

/**
 * {@link Identifier Link text}
 */

/**
 * {@link Identifier.member}
 */

To:

/**
 * {@link module:path/to/module.Identifier Identifier}
 */

/**
 * {@link module:path/to/module.Identifier Link text}
 */

/**
 * Member accessors are not currently linked to, just the root identifier:
 * {@link module:path/to/module.Identifier Identifier.member}
 */

typeof type

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

To:

/**
 * @type {Class<module:path/to/module.exportName>}
 */

Template literal type

/**
 * @type {`static:${dynamic}`}
 */

To:

/**
 * @type {'static:${dynamic}'}
 */

@override annotations

are removed because they make JSDoc stop inheritance

Interface style semi-colon separators

/**
 * @type {{a: number; b: string;}}
 */

To:

/**
 * @type {{a: number, b: string}}
 */

Also removes trailing commas from object types.

TS inline function syntax

/**
 * @type {(a: number, b: string) => void}
 */

To:

/**
 * @type {function(): void}
 */

Bracket notation

/**
 * @type {obj['key']}
 */

To:

/**
 * @type {obj.key}
 */

Tuples

/**
 * @type {[string, number]}
 */

To:

/**
 * @type {Array}
 */

Module id resolution

For resolving module ids, this plugin mirrors the method used by JSDoc:

  1. Parse the referenced module for an @module tag.
  2. If a tag is found and it has an explicit id, use that.
  3. If a tag is found, but it doesn't have an explicit id, use the module's file path relative to the nearest shared parent directory, and remove the file extension.

Contributing

If you are interested in making a contribution to the project, please see the contributing page for details on getting your development environment set up.

Keywords

FAQs

Package last updated on 16 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc