3

I'm having an error while compiling the following code located in a typescript file:

parent.$(mySelector)

Here I'm having an error on the $ sign who is unknown for the typescript compiler. Jquery is referenced through the definition file. What could I do to still be able to use this method of writing my code?

The proper error I'm having is the following:

The property '$' does not exist on value of type 'Window'

1 Answer 1

1

You need to define $ variable for Window object, since JQuery definition file doesn't do that:

interface JQueryWindow extends Window {
    $: JQueryStatic;
}

and whenerver you use Window object cast it to JQueryWindow

(<JQueryWindow>parent).$(selector);
Sign up to request clarification or add additional context in comments.

2 Comments

Further on this I got in another error: (<JQueryWindow>parent).$("").load(function (url, data, complete) { }); --> Supplied parameters do not match any signature of call target (<JQueryWindow>parent).$("").each(function (index, elem) { return this; }); --> ok
i think problem is with load call. according to load signature its: load(url: string, data?: any, complete?: any): JQuery; so your call should be: (<JQueryWindow>parent).$("").load(url, data, complete); where url is the url you want to call, data is optional data you want to send and callback is a callback function that should be called when operation completes

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.