使用Typescript中的Javascript函数 [英] Using a Javascript Function from Typescript
问题描述
我正在尝试用HTML前端构建一个不错的Windows Phone应用程序.我想使用TYPESCRIPT对HTML页面进行处理.有一个JavaScript函数对于我的应用程序的正常运行至关重要-window.external.notify
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
直到我假设运行时才创建此方法,因此我构建了一个javascript包装器函数来确定调用该函数时是否存在.
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);
问题是我需要获取Typescript文件才能看到此功能.我正在使用Visual Studio 2012,并且看到了以下文章-如何在本地模块中使用导出的功能问题是当我只将我的JavaScript文件包含在要使用的功能中时,出现错误TS2095.
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.
错误TS2095:内部版本:找不到符号
error TS2095: Build: Could not find symbol
有什么想法,帮助或可能的SDK可以解决此问题?
Any ideas or help or possible SDKs to circumvent this issue?
推荐答案
您需要告诉Typescript该函数存在于 window.external
上才能使用.因此:
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");
这篇关于使用Typescript中的Javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!