When working with a class and a function that accepts an instance of that class or a similar POJO object, there is a desire to use JSDoc annotations.
class Example {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
/**
* @param {Example} example
*/
function handleExample(example) {
console.log(example.x, example.y);
}
// How can we indicate in JSDoc that both instances of Example and Example-like objects are valid arguments?
handleExample({
x: 'this is x'
});
The use of @param {Example} example
seems to be on the right track, but an error occurs when passing a POJO instead of an actual instance of Example.
Are there any clever JSDoc techniques to clarify that both a specific Example
type and a similar Example
-like object should be accepted?