Reputation: 1031
I have just downloaded the TypeScript documentation. I have a some JavaScript classes and I would like to create and use these class in a TypeScript test application
How can I call a JavaScript function of an included JavaScript from TypeScript. I do not want to create a "d.ts" file. Just to create my classes, call its methods, access its properties.
How do I do that?
I am trying to use kendoUI with TypeScript.
For instance to show a window I have to do:
logonDlg.show();
Example
var logonDlg = $("logonDialog");
if (!logonDlg.data("kendoWindow")) {
logonDlg.kendoWindow(logOnParams);
logonDlg.show();
}
It is working OK. The JS is generated as I want but I receive an error since The property 'kendoWindow' does not exist on value of type 'JQuery'.
How can I disable this kind of error. I could not make, what Ryan said, to work.
Upvotes: 22
Views: 36339
Reputation: 43728
In this particular case you could just include the Kendo UI TypeScript definitions that Telerik provides.
(I realize this question was asked back when the TS definitions probably didn't exist yet, but wanted to add this detail for people who come across this question in the future.)
Upvotes: 4
Reputation: 1031
There is a better solution. Just cast the jQuery logonDlg to any like this:
(<any>logonDlg).kendoWindow(logOnParams);
The code will be a bit different but will work the same.
Both work OK.
Regards
Upvotes: 8
Reputation: 221034
If you want to stop the errors without doing much else extra work, you can 'declare' the objects from your JS code:
declare var w; // implicit type here is 'any'
// (later, anywhere in your file...)
var x = new w(); // you can do whatever you want with w now without getting errors
w.x = 4; // etc.
Upvotes: 24
Reputation: 35257
You just do it. TypeScript won't stop you. You will see warnings in the compiler output but tsc
will generate your JS file just fine.
Upvotes: 4