简体   繁体   English

在外部javascript函数中调用typescript函数

[英]Call typescript function in external javascript function

i have one typescript file with name 'abc.ts' having a method call 'ScanCode()'.我有一个名为“abc.ts”的打字稿文件,有一个方法调用“ScanCode()”。 i have one separate js file "sample.js" having a method foo().我有一个单独的 js 文件“sample.js”,其中包含一个方法 foo()。 i want to call the scancode method of typescript in this sample js' foo method.我想在这个示例 js 的 foo 方法中调用 typescript 的 scancode 方法。

I tried to import ts file in javascript but its not able to idetify 'import' function.我试图在 javascript 中导入 ts 文件,但它无法识别“导入”功能。

You have to compile the typescript file you have to javascript or if you want to import it use something like webpack.您必须将打字稿文件编译为 javascript,或者如果您想导入它,请使用 webpack 之类的东西。 I think that the easiest way to call your typescript function is to make it global.我认为调用 typescript 函数的最简单方法是将其设为全局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM