ThomasReggi
ThomasReggi

Reputation: 59485

How do I assign type as instance of a class using jsdoc?

I have Example class and a something function where the first argument is example, how do I document something so that the example argument is typed as an instance of Example?

class Example {}


function something (example) {

}

Upvotes: 0

Views: 116

Answers (1)

ThomasReggi
ThomasReggi

Reputation: 59485

If the class is discoverable by the function, as in, it's in the same file.

/**
  * @param {Example} example
  */
function something (example) {

}

If jsdoc can't find it, then imports work like this:

/**
  * @param {import('./example')} example
  */
function something (example) {

}

Or this depending on how Example is exported.

/**
  * @param {import('./example')['Example']} example
  */
function something (example) {

}

Upvotes: 1

Related Questions