Is it possible to use JavaScript libraries in TypeScript?
For example I want to use Raphael in TypeScript and added the JS files in my /scripts folder
and added them to _references.js
.
But when I want to declare in my TS file:
var r = Raphael(10,50,640,480);
Intellisense always says:
Raphael does not exist in the current scope.
and the TS file does not compile.
Is it possible to use JavaScript libraries in TypeScript?
For example I want to use Raphael in TypeScript and added the JS files in my /scripts folder
and added them to _references.js
.
But when I want to declare in my TS file:
var r = Raphael(10,50,640,480);
Intellisense always says:
Raphael does not exist in the current scope.
and the TS file does not compile.
Share Improve this question edited May 9, 2013 at 19:53 Tedd Hansen 12.3k14 gold badges62 silver badges100 bronze badges asked Oct 7, 2012 at 14:15 danieldaniel 35.7k40 gold badges107 silver badges162 bronze badges3 Answers
Reset to default 19This line is an ambient declaration:
declare var Raphael: any;
While it works, you get no real typing.
The project DefinitelyTyped already has definitions for Raphael.
Download the raphael.d.ts file.
And use it like this:
/// <reference path="../Definitions/raphael.d.ts" />
I support the previous answer, declare Raphael as var with type any and it will work. But if you seriously like to take benefit of type script, then create declaration file for Raphael js. So, that will provide intellisense whenever you use Raphael js. Here is link for Jquery declaration file which is available in the samples provided by typescript site. Just have a look it will help. Please let me know if any further details required.
As previously, noted, you can just declare Raphael as a var of "any" type, but if you want IntelliSense and compile-time checking, you'll need a declaration file. I've gone ahead and taken an initial stab at this here: https://bitbucket.org/keesey/raphaelts