How can one use @param
to hint the optional param for a function
that is a property (this.selectedPage()
) as well as use @type
to hint its return type?
Take this for example (this.selectedPage()
can receive a page by passing a parameter and return one by passing none):
/**
* @type {function(): Page}
*/
this.selectedPage = ko.observable(data.page);
The type-typehint is nicely picked-up by the IDE and allows for auto-completion of the fact that this.selectedPage()
yields a Page
.
However, please also note that this.selectedPage()
takes a parameter - namely a page. Otherwise the IDE complains that the function allows 0 parameters when trying to pass one.
So I combined the two:
/**
* @type {function(Page): Page}
*/
this.selectedPage = ko.observable(data.page);
This appears to stop the IDE from complaining when trying to pass a parameter, but now it complains when not passing one.
I tried @type {function(undefined|Page): Page}
to no avail.
The function is a getter/setter - so how can one tell the docblock that @param is optional?