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'
4

1 回答 1

1

您需要为 Window 对象定义 $ 变量,因为 JQuery 定义文件不这样做:

interface JQueryWindow extends Window {
    $: JQueryStatic;
}

并且无论何时使用 Window 对象将其转换为 JQueryWindow

(<JQueryWindow>parent).$(selector);
于 2012-11-27T14:06:10.873 回答