englercj / tsd-jsdoc

Compiles JSDoc annotated JavaScript into a Typescript Definition file (.d.ts)
MIT License
316 stars 42 forks source link

Support @event tag #148

Open thw0rted opened 2 years ago

thw0rted commented 2 years ago

Looking around StackOverflow and various blog posts, it seems like the event tag might be one of the least-well-understood tags. Right now, as far as I can tell, tsd-jsdoc just ignores it.

I think it's meant to work similarly to a @typedef -- when I declare an event, I'm saying that the owning function / class / namespace will at some point invoke a callback with an object that has certain properties. That sounds a lot like a TypeScript interface.

What I'm suggesting is that tsd-jsdoc treat these as equivalent:

/**
 * @typedef {Object} Foo.BarEvent
 *
 * An Event with an "x" property
 *
 * @property {number} x
 */
/**
 * An Event with an "x" property
 * @event Foo.BarEvent
 *
 * @type {Object}
 * @property {number} x
 */

In both case an interface called BarEvent should be created in the namespace Foo.