1

I am using VS 2012 and TypeScript with jquery. I am converting an existing JS app into TS and I have the following problem :

$(window).load(function () {
//stuff
});

$(window).load got underlined and error is 'supplied parameters do not match any signature of call target'. I am using jquery 1.7.2 with this jquery.d.ts jquery ts annotations. I added the reference link on top of the file.

What am I doing wrong ?

Edit : I have got typescript installed in VS of course, and it doesn't change anything to edit the argument, it can be "window" or anything else, it keeps making the error. The definition of load() it expects is (url:string, data: any, complete: any) while in jQuery doc it's just a function..

2
  • have you installed typescript for VS2012 Commented Dec 27, 2012 at 11:53
  • Does it accept $(document) in place of $(window)? If so, the d.ts file must only have overloads for document, string and string/object - which means an update to the definition would be needed to allow window. Commented Dec 27, 2012 at 12:44

1 Answer 1

2

The Typescript definition only contains the definition for 1 particular version of the load function, the one that loads html from a url http://api.jquery.com/load/. Typescript is still in alpha don't forget.

This shouldn't affect your use of Typescript, except you will continue to receive the warning.

As an alternative you could change your code to something like the following:

$(window).on("load", function() {
    /// so stuff
});
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, I had the idea that i was the definition of another load method, but I didn't think about using on. I will do that, but for errors in TS the problem is that it doesn't compile in JS at all; is there any way to 'skip' errors which I know aren't real problems ?
One easy way to get around errors like this is to cast the problematic object to <any>, e.g., (<any>$(window)).load(() =>{}).
@KenSmith $(window as any).load(() => {}) is recommended in the latest TypeScript version.

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.