Adding a JS file as a ref to TS file.

Topics: Language Specification
Jul 11, 2014 at 7:47 AM
Hi All,

I am such a newbie to Typescript. I am trying to add a JS file as a ref to a TS file in order to access a plugin.
But i am facing problem.
My JS looks like following:

(function($) {
jQuery.fn.Listener = function(options, callback) {

    //inizializza le variabili
    char0 = new Array("§", "32");........

Now i wanted to call my listener to a TS file. I am trying to do something like this.

declare function Listener(): any;

the above is not able to find the JS file.

Please tell me how to resolve this
Jul 11, 2014 at 6:07 PM
Edited Jul 11, 2014 at 6:08 PM
Using "declare" only means "I promise it will be loaded before this point". It does not trigger any loader. TypeScript transpiles down to JavaScript, and doesn't really do anything special (like loading files). You have to load the required files yourself by either including the script tag(s) for the file(s) before your code loads/executes, or using a loader type library (like RequireJS).
Jul 11, 2014 at 8:49 PM
Exactly what jamesnw said. The 'declare' statements are only about providing type information to the TypeScript compiler so that you can get nice auto completion and compiler errors. They say nothing about where the actual implementation for that type information comes from and how it will be loaded.