@type does not work on functions
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 15.5k
- Forks
- 1.5k
- Avg merge
- 10d 23h
- Merged PRs (30d)
- 1
Description
Input code
(Minimal repro: https://github.com/MattIPv4/jsdoc-method-type)
Working, without @type: a.js
/**
* Test global a
*
* @param {string} one
* @param {number} two
* @returns {string}
*/
const globalA = (one, two) => one.repeat(two);
/**
* Test module a
*
* @module
*
* @param {string} one
* @param {number} two
* @returns {string}
*/
module.exports = (one, two) => one.repeat(two);
Not working, using @type: b.js
/**
* @typedef {function} B
* @param {string} one
* @param {number} two
* @returns {string}
*/
/**
* Test global b
*
* @type {B}
*/
const globalB = (one, two) => one.repeat(two);
/**
* Test module b
*
* @module
* @type {B}
*/
module.exports = (one, two) => one.repeat(two);
JSDoc configuration
Default.
JSDoc debug output
jsdoc src --debug
DEBUG: JSDoc 3.6.10 (Tue, 25 Jan 2022 02:05:39 GMT)
DEBUG: Environment info: {"env":{"conf":{"plugins":[],"recurseDepth":10,"source":{"includePattern":".+\\.js(doc|x)?$","excludePattern":"(^|\\/|\\\\)_"},"sourceType":"module","tags":{"allowUnknownTags":true,"dictionaries":["jsdoc","closure"]},"templates":{"monospaceLinks":false,"cleverLinks":false,"default":{"outputSourceFiles":true}}},"opts":{"_":["src"],"debug":true,"destination":"./out/","encoding":"utf8"}}}
DEBUG: Parsing source files: ["/Users/mattcowley/WebstormProjects/jsdoc-method-type/src/a.js","/Users/mattcowley/WebstormProjects/jsdoc-method-type/src/b.js"]
Parsing /Users/mattcowley/WebstormProjects/jsdoc-method-type/src/a.js ...
Parsing /Users/mattcowley/WebstormProjects/jsdoc-method-type/src/b.js ...
DEBUG: Finished parsing source files.
DEBUG: Adding inherited symbols, mixins, and interface implementations...
DEBUG: Adding borrowed doclets...
DEBUG: Post-processing complete.
Generating output files...
Finished running in 0.20 seconds.
Expected behavior
I would expect @type to behave as the documentation implies, applying the type provided from the typedef to the function.
This would result in the jsdoc output for b.js in the above being almost identical to the jsdoc output for a.js (expect for the naming differences).
Current behavior
When @type is used, the type definition provided is not applied to the function, resulting in the function behaving as if it is undocumented.
a.js |
b.js |
|---|---|
![]() |
![]() |
![]() |
![]() |
The @typedef is detected correctly though, just not applied via @type:

Your environment
| Software | Version |
|---|---|
| JSDoc | 3.6.10 |
| Node.js | 16.14.0 |
| npm | 8.3.1 |
| Operating system | macOS 12.3 |
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the difference between src/a.js and src/b.js by running jsdoc src --debug with the default configuration. Trace how the @typedef {function} B and @type {B} entries are handled, then make the generated documentation for b.js match the documented function behavior shown for a.js.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100



