2016-04-20 7 views
11

Angenommen, Sie den folgenden Code innerhalb einer ES6 Klasse (Dokumentation):Wie erweitert man einen Typedef-Parameter in JSDOC?

/** 
* @typedef Test~options 
* @type {object.<string>} 
* @property {array} elements - An array containing elements 
* @property {number} length - The array length 
*/ 

/** 
* @param {Test~options} opt - Option object 
*/ 
test(opt){ 

} 

Nun möchte ich eine andere Funktion dokumentieren möchte, machen wir es test2 nennen. Diese Funktion nimmt genau das gleiche Objekt options, benötigt aber eine andere Eigenschaft parent.

Wie dokumentiert man dies, ohne redundante Optionen zu dokumentieren? Redundante Mittel:

/** 
* @typedef Test~options 
* @type {object.<string>} 
* @property {array} elements - An array containing elements 
* @property {number} length - The array length 
*/ 

/** 
* @param {Test~options} opt - Option object 
*/ 
test(opt){ 

} 


/** 
* @typedef Test~options2 
* @type {object.<string>} 
* @property {array} elements - An array containing elements 
* @property {number} length - The array length 
* @property {object} parent - The parent element 
*/ 

/** 
* @param {Test~options2} opt - Option object 
*/ 
test2(opt){ 

} 
+0

Referenz auf GitHub: https://github.com/jsdoc3/jsdoc/issues/1199 – dude

Antwort

2

Probieren Sie es

/** 
* @typedef {object.<string>} Test~options 
* @property {array} elements - An array containing elements 
* @property {number} length - The array length 
*/ 

/** 
* @param {Test~options} opt - Option object 
*/ 
test(opt){ 

} 

/** 
* @typedef {Test~options} Test~options2 
* @property {object} parent - The parent element 
*/ 

/** 
* @param {Test~options2} opt - Option object 
*/ 
test2(opt){ 

} 
+0

Dies ist die beste Lösung so weit, weil es das gibt ** Geben Sie ** von 'Test ~ Optionen2' als' Test ~ Optionen' ein und verknüpfen Sie diese mit letzterem. Aber das ist nicht ideal, weil es nicht alle Parameter seines "erweiterten" Typs wiederholt; Es listet nur die neuen Parameter auf. JSDoc sollte an einem besseren Markup dafür arbeiten. – chharvey