Skip to content

@typedef {Object} with function properties: Does not get past "function" (the word), ignores the types #1444

@lll000111

Description

@lll000111

I define a few object types for "API objects", i.e. objects returned by a function that export an "API" from within that functions scope.

Example:

/**
 * `SystemReadStream` objects are created by factory function
 * @global
 * @typedef {Object} SimpleReadStream
 * @property {function((string|ArrayBuffer)):undefined} ondata <b>Assign your event handler</b>
 * @property {function(Error):undefined} onerror <b>Assign your event handler</b>
 * @property {function():undefined} onfinished <b>Assign your event handler</b>
 * @property {function():undefined} pause Pause the read stream
 * @property {function():undefined} resume Resume the read stream
 * @property {function():undefined} close Cancel the read stream
 */

This works in WebStorm:

unbenannt-1

But from JSDoc (using the default template from 3.5.5 with four minor custom CSS rules added) I only get "function", it leaves out all the type information:

unbenannt-2

This is a function syntax used by many, just one of numerous examples (not to mention that WebStorm would not have bothered to support this if that wasn't the case): https://stackoverflow.com/a/38586423/544779

Also, it should be supported at least through the Closure Compiler types, go to "Function Type": https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System or https://github.com/google/closure-compiler/wiki/Annotating-Types#function-declarations or https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#function-type

or go to https://github.com/Microsoft/TypeScript/wiki/JSDoc-support-in-JavaScript "Define function type" (Example)

So... virtually everybody says that this is the syntax to specify a function type, and the IDEs support it too. Only JSDoc doesn't?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions