How can I stop “property does not exist on type JQuery” syntax errors when using Typescript?

后端 未结 7 1237
天涯浪人
天涯浪人 2020-12-01 04:09

I am only using one line of jQuery in my application:

$(\"div.printArea\").printArea();

But this is giving me a Typescript error:

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 04:48

    You could cast it to or extend the jquery typing to add your own method.

     ($("div.printArea")).printArea();
    

    //Or add your own custom methods (Assuming this is added by yourself as a part of custom plugin)

    interface JQuery {
        printArea():void;
    }
    

提交回复
热议问题