Lusito
Lusito

Reputation: 1023

typedoc/jsdoc document generic parameter (callback arguments)

I have the following code:

type AlarmEvent = events.Event<(name: Alarm) => void>;

As you can see, the event class takes a generic parameter in the form of a function signature, which I'd like to document.

Any ideas?

Upvotes: 0

Views: 833

Answers (1)

Sean Vieira
Sean Vieira

Reputation: 159865

If all you need is a place to hang normal JSDocs off of, you can just create another type:

type AlarmHandler = (name: Alarm) => void
type AlarmEvent = events.Event<AlarmHandler>

If you need this to work with JSDoc you can use the @callback tag in a standalone JSDoc comment to do the work:

/**
 * Handles alarm events
 * @callback
 * @param {Alarm} name The alarm that fired
*/

Upvotes: 1

Related Questions