使用var args的Typescript 0.9.5编译失败 [英] Typescript 0.9.5 compilation with var args fails
问题描述
所以我试图在我们的项目中升级到打字稿0.9.5,但是我目前卡住了.
So im trying to upgrade to typescript 0.9.5 in our project, but im currently stuck.
这是从编译器接收到的错误:
This is the error im reciving from the compiler:
error TS2082: Supplied parameters do not match any signature of call target:
Call signatures of types '(event: JQueryEventObject, component: any,
mouseClickPagePosition: any) => void' and
'(eventObject: JQueryEventObject, ...args: any[]) => any' are incompatible:
Call signature expects 1 or fewer parameters.
似乎是这样的代码:
jQuery('selector').on('event',
(event, component, mouseClickPagePosition) => {
// code
});
不能与此jQuery定义一起使用:
cannot be used with this jQuery definition:
on(events: string, handler: (eventObject: JQueryEventObject, ...args: any[]) => any): JQuery;
但是方法签名似乎加起来了?
But the method signatures seems to add up?
推荐答案
此代码
jQuery('selector').on('event',
(event, component, mouseClickPagePosition) => {
// code
});
应这样写:
jQuery('selector').on('event',
(event, component?, mouseClickPagePosition?) => {
// code
});
on
上的回调函数指定将使用至少一个参数调用它,并且可能更多.回调提供了必需三个参数,因此被视为错误.
The callback on on
specifies that it will be called with at least one parameter, and possibly more. The callback provided required three parameters, so it's considered an error.
仅在0.9.5之前意外地允许使用此代码,但鉴于这是多么令人讨厌/不直观,将其视为允许必需"这些参数而不是可选参数的设计更改.
This code was only accidently allowed pre-0.9.5, but given how annoying/unintuitive this is, it's being considered as a design change to allow these parameters to be 'required' instead of optional.
这篇关于使用var args的Typescript 0.9.5编译失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!