最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

visual studio 2012 - Use Raphael JavaScript library in TypeScript - Stack Overflow

programmeradmin3浏览0评论

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 badges
Add a comment  | 

3 Answers 3

Reset to default 19

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" />

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

发布评论

评论列表(0)

  1. 暂无评论