Typescript: Required callback parameters?

后端 未结 2 1341
别跟我提以往
别跟我提以往 2020-12-21 05:58

I want to define a function which takes a callback as a parameter, and that callback\'s parameters should be required. Typescript correctly reports a callback with a mismatc

2条回答
  •  天命终不由人
    2020-12-21 06:36

    There isn't a way to do this.

    Callbacks with fewer parameters than the caller provides are extremely common in JavaScript - functions like forEach, map, filter, etc all provide 3 or more arguments but are frequently given 1-parameter functions as callbacks.

提交回复
热议问题