admin管理员组文章数量:1357082
Let's say I have a javascript file, myScript.js, with the following content:
function run(file) {
// some operations
}
How can I use the 'run' function inside a TypeScript file?
I've read similar questions but didn't find their answers clear enough: where I declare the function? how do I reference the declaration file etc..
Let's say I have a javascript file, myScript.js, with the following content:
function run(file) {
// some operations
}
How can I use the 'run' function inside a TypeScript file?
I've read similar questions but didn't find their answers clear enough: where I declare the function? how do I reference the declaration file etc..
Share Improve this question edited Jul 4, 2016 at 10:33 yonisha asked Jul 4, 2016 at 10:03 yonishayonisha 3,0962 gold badges26 silver badges33 bronze badges 3- You need to write a declaration file for that script – Nitzan Tomer Commented Jul 4, 2016 at 10:05
- 1 Possible duplicate of Using a 3rd party js file with TypeScript – Nitzan Tomer Commented Jul 4, 2016 at 10:06
- I think that the other answers are not details enough. Where should I declare it? where is the reference to the js file? That's the information I'm looking for – yonisha Commented Jul 4, 2016 at 10:21
1 Answer
Reset to default 5TypeScript does not know about the run
function. You'll have to declare it:
declare function run(file: any): any;
Now this works:
run(myFile);
EDIT: you can also look into using "--allowJs" tsc parameter mentioned here, but I have no experience with it.
EDIT 2: If the external script is a published library, chances are that there is a typings file (.d.ts) for it. Check out the typings tool in that case.
本文标签: Using external javascript script in TypeScriptStack Overflow
版权声明:本文标题:Using external javascript script in TypeScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744073119a2586249.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论