Introduction
- JSDoc documentation (jsdoc.app)
- Block tags (jsdoc.app)
Functions
/**
* This is a function.
*
* @param {string} n - A string param
* @param {string} [o] - An optional string param
* @param {string} [d=DefaultValue] - An optional string param
* @return {string} A good string
*
* @example
*
* foo('hello')
*/
function foo(n, o, d) {
return n
}
See: JSDoc documentation (jsdoc.app)
Types
| Type | Description |
|---|---|
@param {string=} n | Optional |
@param {string} [n] | Optional |
@param {string} [n="hi"] | Optional with default |
@param {(string|number)} n | Multiple types |
@param {*} n | Any type |
@param {...string} n | Repeatable arguments |
@param {string[]} n | Array of strings |
@return {Promise<string[]>} n | Promise fulfilled by array of strings |
See: Type tags (jsdoc.app)
Variables
Typedef
/**
* A song
* @typedef {Object} Song
* @property {string} title - The title
* @property {string} artist - The artist
* @property {number} year - The year
*/
/**
* Plays a song
* @param {Song} song - The {@link Song} to be played
*/
function play(song) {}
See: @typedef (jsdoc.app)
Typedef shorthand
/**
* A song
* @typedef {{title: string, artist: string, year: number}} Song
*/
/**
* Plays a song
* @param {Song} song - The {@link Song} to be played
*/
function play(song) {}
See: @typedef (jsdoc.app)
Importing types
/**
* @typedef {import('./Foo').default} Bar
*/
// or
/** @import { Bar } from "./Foo.js" */
/**
* @param {Bar} x
*/
function test(x) {}
This syntax is TypeScript-specific.
See: JSDoc-supported types (typescriptlang.org)
Other keywords
/**
* @throws {FooException}
* @async
* @private
* @deprecated
* @see
* @example
* @todo
*
* @function
* @class
*/
See: Block tags (jsdoc.app)
0 Comments for this cheatsheet. Write yours!