Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
jsdoc-tsimport-plugin
Advanced tools
A JSDoc plugin to support the Typescript import syntax.
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.
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.
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. |
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"
}
}
}
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
.
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.
This references the issues:
FAQs
A JSDoc plugin to support the typescript module import syntax.
The npm package jsdoc-tsimport-plugin receives a total of 2,244 weekly downloads. As such, jsdoc-tsimport-plugin popularity was classified as popular.
We found that jsdoc-tsimport-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.