最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Argument of type 'void' is not assignable to parameter of type 'Function' - Stack O

programmeradmin7浏览0评论

Im tryin to pass the parameter 'this' to a function this way:

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

and the Confirmation Class is like this:

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

But i keep getting the error:

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

So, i don't know what is the problem and what should i do.

Im tryin to pass the parameter 'this' to a function this way:

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

and the Confirmation Class is like this:

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

But i keep getting the error:

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

So, i don't know what is the problem and what should i do.

Share Improve this question asked Oct 16, 2017 at 12:24 Hely Saul ObertoHely Saul Oberto 5971 gold badge11 silver badges23 bronze badges 1
  • You are passing the value returned by calling this.changea(this) and the value of this.changer. What are they? BTW, "void" is not an ECMAScript Type. – RobG Commented Oct 16, 2017 at 12:32
Add a ment  | 

1 Answer 1

Reset to default 6

The second argument you are passing is this.changea(this) - the result of this is that you are passing the return value of te changea function, not the function itself.

If you want to pass a function as the argument, and preserve the meaning of this, you can use:

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

You have now wrapped your code in a function, that hasn't yet been executed.

发布评论

评论列表(0)

  1. 暂无评论