Using a Javascript Function from Typescript Using a Javascript Function from Typescript typescript typescript

Using a Javascript Function from Typescript


//notif.js

let notify = function(message) {    alert(message);}

//test.ts

declare function notify(message: string): any;if(notify != undefined)    notify("your message");

Make sure notif.js is loaded first.


You need to tell typescript that this function exists on window.external in order to use it. So :

interface External{    notify: Function;}if (window.external.notify != undefined)    window.external.notify("your message");