I'm wondering how to get rid of Typings/TypeScript errors like:
Property 'modal' does not exist on type 'JQuery'.
As far as I know I've properly installed the latest typings for JQuery and it is definitely finding and using them (I have tested this). The 'modal' property is actually a function I'm calling like:
$('#popup').modal();
// modal() is part of the Semantic UI library which is available and works in my browser
Please note I'm using the latest version of Typings v1.0.4 which seems to prefer using globalDependencies
rather than "ambient" types. My typings.json file:
{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160317120654",
"jasmine": "registry:dt/jasmine#2.2.0+20160505161446",
"jquery": "registry:dt/jquery#1.10.0+20160417213236",
"node": "registry:dt/node#4.0.0+20160509154515",
"source-map": "registry:dt/source-map#0.0.0+20160317120654",
"uglify-js": "registry:dt/uglify-js#2.6.1+20160316155526",
"webpack": "registry:dt/webpack#1.12.9+20160523035535"
}
}
Is there any way I can tell typings that functions like modal() and many others are actually OK and to not throw errors?
UPDATE:
Per the answer below I resolved these errors by adding the following to a custom typings file that I load custom-typings.d.ts
interface JQuery {
modal: (cmd?: string, options?: any) => JQuery;
dropdown: () => void;
checkbox: () => void;
calendar: (options?:any) => void;
}
This tells Typescript that JQuery object has extra functions available to it: modal(), dropdown(), etc.
You will notice that for my modal definition I specify two optional variables that can be passed in (since this is the behavior of the Semantic UI modal() function that I'm using). Also the modal() function returns another JQuery object recursively because the real one acts this way as well--which allows me to call it multiple times in a chain:
$('#someId').modal('setting', {autoFocus: true}).modal('show')
Nothing is wrong. You get this error because modal()
doesn't appear in jquery.d.ts
. To get rid of this error message, see Converting a jQuery plugin to TypeScript