如何引用另一个 TypeScript 文件中的类?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17242468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to reference a class in another TypeScript file?
提问by Ian Boyd
How do i get access to classes in another .ts
file in TypeScript?
如何访问.ts
TypeScript中另一个文件中的类?
e.g.
例如
app.ts
应用程序
window.onload = () => {
/// <reference path="TilingEngine/SofRenderer.ts" >
var drawingTool = new SofRenderer();
};
TilingEngine/SofRenderer.ts
TilingEngine/SofRenderer.ts
class SofRenderer {
}
Fails to compile, with the error:
编译失败,报错:
Could not find symbol 'SofRenderer'.
找不到符号“SofRenderer”。
See also
也可以看看
- How can I import an external file with TypeScript?(i'm not using node)
- How do I import other TypeScript files?(i'm not using modules)
- 如何使用 TypeScript 导入外部文件?(我没有使用节点)
- 如何导入其他 TypeScript 文件?(我没有使用模块)
回答by Fenton
Your reference comment should be at the top of your file and be self-closing. Like this:
您的参考评论应位于文件顶部并自动关闭。像这样:
///<reference path="TilingEngine/SofRenderer.ts" />
window.onload = () => {
var drawingTool = new SofRenderer();
};