0
說我有一個字符串數組。JSDoc類型等於數組的成員
/** @type Array.<string> */
var possibleValues = ['a','b','c','d'];
我有一個接受字符串的函數,但我只希望它是等於possibleValues
成員之一。
/**
* It does nothing.
* @param {string} input One of the members of `possibleValues`.
* @returns {string} Same as your input, useless... or is it?
*/
function nothing(input) { return input; }
是否有JSDoc 3一種方法,我可以在input
參數的類型明確設定爲possibleValues
的一個值?
最好我想引用原始數組,而不僅僅是在評論中列出其成員,因爲我可能會重用它,它可能會稍後進行更改。
我根據你的措辭,該陣列是不是在運行時更改猜測(否則我也沒指望你提爲「列表中的成員」因爲靜態的值列表會導致誤導),但我不能100%確定我是對的。 – Louis
@Louis它在運行時不會改變,通過_「可能改變」_我的意思是在未來版本的應用程序中。 –
可能是'@ typedef'標記(http://usejsdoc.org/tags-typedef.html)可以幫助您引用它。 – krampstudio