2017-10-16 83 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

谢谢,这工作完美 –

相关问题