Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
917 views
in Technique[技术] by (71.8m points)

jquery - Typescript 0.9.5 compilation with var args fails

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.

It seems like this code:

jQuery('selector').on('event',
            (event, component, mouseClickPagePosition) => {
              // code
            });

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This code

jQuery('selector').on('event',
            (event, component, mouseClickPagePosition) => {
              // code
            });

should be written as this instead:

jQuery('selector').on('event',
            (event, component?, mouseClickPagePosition?) => {
              // code
            });

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...