I have a JavaScript file (TestAdd.js), containing a function that I'd like to use from within a TypeScript file (CalcTest.ts)
Here is the JavaScript:
var TestSum;
(function (TestSum) {
var Cal = (function () {
function Cal() {
}
Cal.prototype.doAdd = function (a, b) {
return a + b;
}
})
})
And here is the TypeScript:
/// <reference path = "Calc.d.ts" />
var obj = new TestAdd.Cal();
console.log("Add: " +obj.doAdd(40, 25));
I've created an ambient declaration file (Calc.d.ts) to declare the external module:
declare module TestAdd{
export class Cal {
doAdd(a:number, b:number) : number;
}
}
My understanding from following several tutorials is that this should allow me to instantiate the type and use the method from the external JS file. I'm expecting the result of 65 to be logged to the console, but I am instead getting ReferenceError: TestAdd is not defined.