如果我正確地理解了你,你的解決方案將取決於「第二個」函數返回的類型。
概括地說,至少有2種方式來做到這一點:
- lambda語法
- 接口(正常和通用接口)
我試圖解釋這一切在下面的代碼中,請檢查它:
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;
}
}
'Function'不會返回類型嗎? – tymeJV
如果可能,我想指出第二個函數的返回類型。 '功能'雖然工作。 – jordan