I want override jsdoc for function which inheritance from base class.
the function adds parameter to base function.
parent:
export default class Base {
/**
* Function apply().
*
* Apply the hook.
*
* #param {{}} args
*
* #returns {Boolean}
*/
apply( args ) {
throw Error( 'apply() must be implanted.' );
}
}
child:
export default class Child extends Base {
/**
* how to override jsdoc and point out that i
* have added containers param?
*/
apply( args, containers ) {
}
}
#override tag will be useful i think. https://jsdoc.app/tags-override.html for reference
Related
I'm using the documentation package, but cannot figure out how to get it to document class properties (that aren't defined via getters and setters).
As the following just generates class documentation for SomeClass, but omits the someProperty documentation.
/**
* SomeClass is an example class for my question.
* #class
* #constructor
* #public
*/
class SomeClass {
constructor () {
this.someProperty = true // how do I document this?
}
/**
* someProperty is an example property that is set to `true`
* #property {boolean} someProperty
* #public
*/
}
An aside: the #constructor on the class jsdoc is a documentation thing.
Move the JSDoc for someProperty into the constructor where it is first defined:
/**
* SomeClass is an example class for my question.
* #class
* #constructor
* #public
*/
class SomeClass {
constructor () {
/**
* someProperty is an example property that is set to `true`
* #type {boolean}
* #public
*/
this.someProperty = true
}
}
I'm unsure if there is a way of accomplishing it with the documentation package using an approach that doesn't involve inlining the JSDocs into the constructor.
Another way is to declare them in class documentation as follows:
/**
* Class definition
* #property {type} propName - propriety description
* ...
*/
class ClassName {
constructor () {...}
...
}
You can declare properties in a class, and use #type to declare a type for them. Worked in VSCode 1.70.2 with in a plain ECMAScript Module.
class Foo {
/**
* Some bary data
* #type { BarClass }
*/
bar;
}
let f = new Foo();
f.bar; // Intellisense can tell you type and purpose
Assumed this ...
`use strict;`
class Foo
{
/**
* Description
* #param {Type} arg blabla
*/
doSomething( arg )
{
}
}
class Bar extends Foo
{
/**
* Overwrite the description for `doSomething()` without redeclaring the method itself.
* #param {Type} arg blabla
*/
// dosomething( arg )
// {
// }
}
This is a very simplified nonsense example. The reason in reallife is ...
I have a common collection which accepts mixed elements for some methods like add, replace, remove, etc.. I have a second collection specialized for managing HTTP headers. E. g. I like to change the doc of the add() from "Adds an element to the collection" to "Adds an HTTP header to the collection". The method itself stays as is.
I tried
class Bar extends Foo
{
/**
* Overwrite the description for `doSomething()` without redeclaring the method itself.
* #param {Type} arg blabla
* #method dosomething
* #memberOf {Foo}
*/
}
in various ways ... with #override, #inheritdoc, etc.
How to achieve this?
When I declare a class with ctor, and then use this class only as a function's input parameter, I get no-unused-vars from eslint.
Code:
/**
* A class
*/
class SampleClass{
/**
* Ctor
* #param {string} par - a parameter
*/
constructor(par) {
this.par = par;
}
}
/**
* Func
* #param {SampleClass} param - a sample class
* #returns {SampleClass} - the same class
*/
function fName(param) {
return param;
}
So as you can see, I use SampleClass both as input parameter and as return type of the function, but eslint shows error: 'A class "SampleClass" is defined but never used. eslint no-unused-vars'
How can i fix this? Of course, I need to leave this type of check workong.
I couldn't fully understand what you wanted to do with that function and class, but within my understanding, I think this would work
class SampleClass {
constructor(par){
this.par = par;
}
getInstance() {
return this.par
}
}
function fName(params) {
return params
}
const newClass = new SampleClass("param");
fName(newClass.getInstance())
I found that I need to use a cleverer eslint parser - #babel/eslintparser. It does not raise this error when I use classes.
In ES6/ES2015, using interfaces and implementations (#interface and #implements),
Is specifying that a parameter is optional part of the interface or the implementation?
If part of the interface, what about specifying the default value for the optional parameter?
In Scenario A, transpiling to ES5 with JSCompiler will object to the interface for otherMethod with ERROR - interface member functions must have an empty body (i.e. that the default value is syntactic sugar for preface code that sets a parameter's value when the value is undefined)
Are the answers the same whether ES5 or ES6?
Scenario A
/**
* #interface
*/
class SomeInterface {
/**
* #param (boolean=) someArgument
*/
someMethod(someArgument) {}
/**
* #param (boolean=) someArgument
*/
otherMethod(someArgument = false) {}
}
/**
* #implements {SomeInterface}
*/
class SomeImplementation {
/** #override */
someMethod(someArgument = false) {
// do something
}
/** #override */
otherMethod(someArgument = false) {
// do something
}
}
Scenario B
/**
* #interface
*/
class SomeInterface {
/**
* #param (boolean) someArgument
*/
someMethod(someArgument) {}
}
/**
* #implements {SomeInterface}
*/
class SomeImplementation {
/**
* #param (boolean=) someArgument
* #override
*/
someMethod(someArgument = false) {
// do something
}
}
How do I document a member function from a father class. There is a class A with a member function Afunc(), and I am gonna document class B extends A.
I do not overwrite Afunc() in B, yet I need the function Afunc() appear in my document, how do I do it?
I wrote
/**
* description
* #function Afunc
* #memberOf A
*/
It works that appears Afunc in the document, yet there is a <static> tag at the start of the function name.
How do I solve it?
Thanks everyone.
jsdoc 3.2.2 does what you want by default. In this example, the method B.foo will automatically be documented because B extends A and does not override foo:
/**
* #class
*/
function A() {
}
/**
* Foo the flerbl.
* #param {Object} flerbl The flerbl.
*/
A.prototype.foo = function (flerbl) {
};
/**
* #class
* #extends A
*/
function B() {
}
B.prototype = new A();
Otherwise, you must use # in your #memberof tag to mark the object as an belonging to an instance of the class:
/**
* description
* #function Afunc
* #memberof A#
*/