簡體   English   中英

類型“ void”的參數不能分配給“功能”類型的參數

[英]Argument of type 'void' is not assignable to parameter of type 'Function'

我試圖通過這種方式將參數'this'傳遞給函數:

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

確認類是這樣的:

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

但我不斷收到錯誤:

類型“ void”的參數不能分配給“功能”類型的參數

所以,我不知道問題出在哪里,我該怎么辦。

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

如果要傳遞函數作為參數,並保留this的含義,則可以使用:

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

現在,您已將代碼包裝在尚未執行的函數中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM