![](/img/trans.png)
[英]Visual Studio Code Intellisense Method Definitions Javascript
[英]Javascript overload functions detect by visual studio code intellisense
如何編寫可被Visual Studio代碼intellisense檢測到的javascript重載函數,以及如何對其進行文檔化。
例如,茉莉花的it()函數如下所示。
功能(期望:字符串,斷言?:(完成:DoneFn)=>無效,超時?:數字):無效(+1重載)
茉莉花實際上沒有定義兩個方法(一個重載另一個)。 在IDE中看到該文本的原因是鍵入文件聲明了兩個版本,以提供不同的用法。 例如,這是舊版本的DefinitelyTyped如何設置it()
函數的方式:
// Type definitions for Jasmine 1.3
// ...
declare function it(expectation: string, assertion: () => void): void;
declare function it(expectation: string, assertion: (done: (err?: any) => void) => void): void;
作為參考,下面是該版本的Jasmine中的相關代碼,以表明只有一個函數可以處理這兩種用例:
/**
* Creates a Jasmine spec that will be added to the current suite.
*
* // TODO: pending tests
*
* @example
* it('should be true', function() {
* expect(true).toEqual(true);
* });
*
* @param {String} desc description of this specification
* @param {Function} func defines the preconditions and expectations of the spec
*/
var it = function(desc, func) {
return jasmine.getEnv().it(desc, func);
};
if (isCommonJS) exports.it = it;
jasmine.Env.prototype.it = function(description, func) {
var spec = new jasmine.Spec(this, this.currentSuite, description);
this.currentSuite.add(spec);
this.currentSpec = spec;
if (func) {
spec.runs(func);
}
return spec;
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.