I am only using one line of jQuery in my application:
$("div.printArea").printArea();
But this is giving me a Typescript error:
The property 'printArea' does not exist on type JQuery?
Can someone tell me how I can stop this error appearing?
You could cast it to <any> or extend the jquery typing to add your own method.
(<any>$("div.printArea")).printArea();
Or, add your own custom methods (Assuming this is added by yourself as a part of custom plugin)
declare global {
interface JQuery {
printArea(): void;
}
}
Error:(44, 23) TS2339: Property 'printArea' does not exist on type 'ElementFinder'.interface JQuery way in an external module and define a function parameter as a JQuery type and attempt to call it from another file, TypeScript will complain that there's two types named JQuery that are unrelated.declare global { ... } around the interface declaration.For your example, you'd add this:
interface JQuery{
printArea():void;
}
Edit: oops, basarat is correct below. I'm not sure why I thought it was compiling but I've updated this answer.
$.inviewport(el) Ops case $('selector').printArea$('selector').printArea compiles? I don't think so. $.printArea will compile though. You have been very polite so no offence taken or intended :)Since printArea is a jQuery plugin it is not included in jquery.d.ts.
You need to create a jquery.printArea.ts definition file.
If you create a complete definition file for the plugin you may want to submit it to DefinitelyTyped.
/// <reference path="jquery.extension.js" /> at the top of the file, isn't IntelliSense supposed to read that file and infer that code just as if I'd written it in my file? Instead, it's still flagging errors on my valid code.jquery.extension.js is not declaring new types to overwrite existing types (something IntelliSense would read), but it's programmatically extending the types, and IntelliSense isn't smart enough to determine the end result of that code. Ugh. I really don't want to write a whole type file for this massive library.