Run a javascript function within a typescript file

0

I have the following problem, I currently have a project that has some files in typescript and others in javascript -

my folder structure is as follows For everything that is javascript, files .js

js/src 

For everything that is typescript, files .ts

js/typescript

I have also configured my project so that everything that is as typescript is compiled into a folder

js/bin/compiled

For now I have two files siteController.ts

class SiteController {
    eventManager:any;

    constructor(message: string) {
        this.eventManager = new EventManager(this);
    }
} 

and test.js

var test = function()
{
    console.log("se ejecuto test");
}
var siteCOntroller = new SiteController("test");

Now, my problem is as follows If from test.js instancio siteController everything works fine, without throwing any error

If from siteController.ts I call the test () function; which is defined as seen in the file test.js

The compiler gives me the following error:

js/typescript/siteController.ts(6,9): error TS2304: Cannot find name 'test'.

I do not finish understanding where the problem is, as an example and if it is useful, leave my code here:

staging.mdiconcept.com/intercambio/dev_test_typescript_deploy.rar

Thank you very much

    
asked by Pablo 05.05.2017 в 22:45
source

1 answer

1

You can make calls to JavaScript functions in external files. You simply need to declare the function for typescript to know they exist.

Well as anonymous type variable:

declare var test;

or interface type:

interface __test { }
declare var test: __test;

You can also include this in a declarations file but it is not mandatory.

    
answered by 05.05.2017 в 23:47