2017-10-16 13 views
1

javascriptの関数への入力パラメータを文書化しようとしていますが、jsdocでそれを行う方法を考えることができません。jsdocとvscode:別の関数の引数として渡された関数のドキュメント化

私は、@callbackコメントを使用する必要があることを示唆しているjsdocのドキュメントを見てきましたが、Visual Studio Code(vscode)はスクリーンショットのとおり強調表示していません。

location

パラメータのインテリセンスは、タイプlocatorLocationを返すidのパラメータを有する関数)のではなく、anyを入力だことを示しています。

shows the locater parameter not being type hinted

パラメータとして渡された関数を呼び出す関数を示し例コード:

class Location { 
    constructor(position, count) { 
    this.position = position; 
    this.count = count; 
    } 
} 

const items = { 
    'USB Cable': new Location('Desk Drawer', 123), 
    Keyboard: new Location('Desk Surface', 1), 
}; 

/** 
* A locater. 
* @param {string} id 
* @returns {Location} 
*/ 
const locaterA = id => items[id]; 

/** 
* Finds the item by its unique id. 
* @callback locater 
* @param {string} id 
* @returns {Location} 
*/ 

/** 
* Attempt to find the item with the given locater. 
* @param {string} id 
* @param {locater} locater 
*/ 
const locate = (id, locater) => locater(id); 

const result = locate('USB Cable', locaterA); 

console.log(result); 

これは、私がやっている何の問題ですvsdocは、ユースケース、またはvscodeをサポートしていませんそれをサポートしていない?

答えて

1

VscodeのIntelliSenseは@callbackをサポートしていません。ここで追跡されています:https://github.com/Microsoft/TypeScript/issues/7515

便利な回避策として、あなたは@typedef使用することができます。

/** 
* Finds the item by its unique id. 
* @typedef {function(string): Location} Locater 
*/ 

/** 
* Attempt to find the item with the given locater. 
* @param {string} id 
* @param {Locater} locater 
*/ 
const locate = (id, locater) => locater(id); 

enter image description here

1

JSDoc自体で正しく使用しているようです。しかし、Visual Studioは、@callbackを含まない、限定されたJSDocのサブセットのみをサポートしているようです。https://msdn.microsoft.com/en-us/library/mt162307.aspx

私はVisual Studioを手軽に利用できませんが、Googleクローズスタイルを試してみることもできますこれは次のようになります:

@param { function(string) : number } locator 

これは、文字列を受け取り、数値を返す関数だと言います。

このドキュメントは、https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler(該当するセクションにジャンプするには「Function Return Type」を検索してください)をご覧ください。

少なくとも、私はJetBrainsにその構文をサポートしていることに気付きました。

関連する問題