最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Using a Javascript Function from Typescript - Stack Overflow

programmeradmin1浏览0评论

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 function which is crucial for my application to work - window.external.notify

This method isn't created till runtime I assume, so I build a javascript wrapper function to determine if it exists when it is called.

if (window.external.notify != undefined)
    window.external.notify(msg);

The issue is I need to get my Typescript files to see this function. I am using Visual Studio 2012 and I have seen the post - How to use an exported function within the local module The issue is when I just include my javascript file with the function I want to use I get the error TS2095.

error TS2095: Build: Could not find symbol

Any ideas or help or possible SDKs to circumvent this issue?

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 function which is crucial for my application to work - window.external.notify

This method isn't created till runtime I assume, so I build a javascript wrapper function to determine if it exists when it is called.

if (window.external.notify != undefined)
    window.external.notify(msg);

The issue is I need to get my Typescript files to see this function. I am using Visual Studio 2012 and I have seen the post - How to use an exported function within the local module The issue is when I just include my javascript file with the function I want to use I get the error TS2095.

error TS2095: Build: Could not find symbol

Any ideas or help or possible SDKs to circumvent this issue?

Share Improve this question edited May 23, 2017 at 12:34 CommunityBot 11 silver badge asked Feb 4, 2014 at 5:49 MrSteamfistMrSteamfist 631 gold badge1 silver badge5 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 8

//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");
发布评论

评论列表(0)

  1. 暂无评论