Using a Javascript Function from Typescript

前端 未结 2 1333
暖寄归人
暖寄归人 2020-12-20 20:35

I am trying to build a nice windows phone application with an HTML front end. I want to use TYPESCRIPT to do my processing onto my html page. There is one javascript funct

相关标签:
2条回答
  • 2020-12-20 21:18

    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");
    
    0 讨论(0)
  • 2020-12-20 21:29

    //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.

    0 讨论(0)
提交回复
热议问题