Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Raphael JavaScript library in TypeScript

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.

like image 233
daniel Avatar asked Oct 07 '12 14:10

daniel


1 Answers

This 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" />
like image 74
Boris Yankov Avatar answered Oct 20 '22 07:10

Boris Yankov