2

Using Typescript, I am having difficulty with an event.

The event raises like this...

$(this).trigger('customEvent', { page: index });

This has always worked fine in Javascript. But my wiring to this is not working in Typescript when I try to get the parameters...

$(someSelector).on('customEvent', (e, page) => {
   // do some stuff with page or e
});

It just refuses to let me have the two parameters. But the standard e does not contain all of the information I need for this to work right.

1 Answer 1

3

This is be cause of the signature defined for event handlers. All members after the first are optional see : https://github.com/borisyankov/DefinitelyTyped/blob/master/jquery/jquery.d.ts?source=c#L2280

Therefore make page optional (using ?):

$(someSelector).on('customEvent', (e, page?) => {
   // do some stuff with page or e
});
Sign up to request clarification or add additional context in comments.

1 Comment

THANK YOU. YOU ARE A GOD AMONG INSECTS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.