Here is the situation:
I have an old third party javascript function and I want to use it in my typescript codes simply using ambient declaration:
old.js: (is loaded by <script> in my .aspx file)
function myFunc() {
return “Hello World”;
}
typing.d.ts:
export declare function myFunc(): string;
app.ts
import { myFunc } from “./typing”
let str: string = myFunc()
transpild app.js:
var str = typing_1.myFunc();
There is no issue in compile time but in runtime I get this error: ‘myFunc is not a function’
Any help will be appreciated
So many appreciate @AluanHaddad for his comments toward fixing the issue. Here is the answer:
Need to rename typing.d.ts to old.d.ts and put it in the same folder that old.js resides. This is due to the old.js just includes global and doesn't have any export