2015-11-25 100 views
10

我正在使用Typescript開發量角器測試。看起來量角器可用的d.ts文件已經過時了。我正在嘗試將其更新爲包含「預期條件」量角器添加的內容。 (http://www.protractortest.org/#/api?view=ExpectedConditions) 總而言之,預期條件是量角器內的一組函數,它返回一個返回值的承諾的函數。返回另一個函數的函數的返回類型是什麼

用法的例子:

protractor.ExpectedCondtions.visibilityOf(element(by.id('button1')))(); 

我難倒就如何告訴我返回,將返回一個特定的返回類型的函數量角器。有人對這個有經驗麼?

+0

'Function'不會返回類型嗎? – tymeJV

+0

如果可能,我想指出第二個函數的返回類型。 '功能'雖然工作。 – jordan

回答

12

如果我正確地理解了你,你的解決方案將取決於「第二個」函數返回的類型。

概括地說,至少有2種方式來做到這一點:

  1. lambda語法
  2. 接口(正常和通用接口)

我試圖解釋這一切在下面的代碼中,請檢查它:

module main 
{ 
    export class TestClass 
    { 
     // Use lamba syntax as an interface for a return function 
     protected returnSpecificFunctionWhichReturnsNumber():() => number 
     { 
      return this.specificFunctionWhichReturnsNumber; 
     } 

     protected specificFunctionWhichReturnsNumber(): number 
     { 
      return 0; 
     } 

     // Use an interface to describe a return function 
     protected returnSpecificInterfaceFunction(): INumberFunction 
     { 
      return this.specificFunctionWhichReturnsNumber; 
     } 

     // Use a generic interface to describe a return function 
     protected returnSpecificGenericInterfaceFunction(): IReturnFunction<number> 
     { 
      return this.specificFunctionWhichReturnsNumber; 
     } 
    } 

    // An interface for a function, which returns a number 
    export interface INumberFunction 
    { 
     (): number; 
    } 

    // A generic interface for a function, which returns something 
    export interface IReturnFunction<ValueType> 
    { 
     (): ValueType; 
    } 
}