DEV Community

Discussion on: Type safety in JavaScript with JSDoc and VSCode

Collapse
yashaka profile image
Iakiv Kramarenko • Edited on

Hey!

How can I add type hint to the object that is a generic function?

I want something like:

/**
 * @callback ReturnsJQuery
 * @returns {JQuery<E>}
 * @template {Node} E
 */

/** 
 * @type ReturnsJQuery<E>
 * @template {Node} E
 */
this.fn = ...
Enter fullscreen mode Exit fullscreen mode

or

/**
 * @typedef {() => JQuery<E> } ReturnsJQuery
 * @template {Node} E
 */

/** 
 * @type ReturnsJQuery<E>
 * @template {Node} E
 */
this.fn = ...
Enter fullscreen mode Exit fullscreen mode

is something like this even possible?

Collapse
t7yang profile image
t7yang Author

If you want to define class method, please see the "Type class and this" section, you should not define the method when assigning value.

If you use prototype based paradigm rather than class, you can check this page. The generic type definition remain same.