如何引用另一个 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:49:41  来源:igfitidea点击:

How to reference a class in another TypeScript file?

typescript

提问by Ian Boyd

How do i get access to classes in another .tsfile in TypeScript?

如何访问.tsTypeScript中另一个文件中的类?

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

也可以看看

回答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();
};