2017-10-16 121 views
0

林試着的參數的參數「這個」這種方式傳遞給一個函數:參數類型「無效」的是不能分配給類型「功能」

modalshow = new Confirmation(false, this.changea(this), this.changer); 

和確認類是這樣的:

constructor(
    public show: boolean, 
    public actionAccept: Function, 
    public actionReject: Function 
) {} 

,但我不斷收到錯誤:

Argument of type 'void' is not assignable to parameter of type 'Function'

所以,我不知道是什麼問題,我應該做。

+0

您正通過調用'this.changea(this)'返回的**值**和'this.changer'的**值**。他們是什麼?順便說一句,「void」不是[ECMAScript * Type *](http://ecma-international.org/ecma-262/8.0/#sec-ecmascript-language-types)。 – RobG

回答

1

您傳遞的第二個參數是this.changea(this) - 這樣做的結果是您傳遞te changea函數的返回值,而不是函數本身。

如果你想傳遞一個函數作爲參數,並保存的this的意思,你可以使用:

modalshow = new Confirmation(false,() => this.changea(this), this.changer); 

您現在已經包裹在一個函數代碼,還沒有被執行。

+1

謝謝,這工作完美 –

相關問題