简体   繁体   English

打字稿导入类

[英]Typescript import class

I have been trying to get this thing to work for quite a while now, and so far no solution that I have found has worked for me. 我一直在尝试使该功能工作一段时间,到目前为止,我发现没有找到适合我的解决方案。

This is what I have: 这就是我所拥有的:

//Test.ts
module t
{
    export class Test
    {
        constructor ()
        {
            alert("test");
        }
    }
}

//Main.ts
/// <reference path="Test.ts" />

var test: t.Test = new t.Test();

As you can see I have two files, one is Main.ts and the other one is Test.ts. 如您所见,我有两个文件,一个是Main.ts,另一个是Test.ts。 They are both in the same folder. 它们都在同一个文件夹中。 Also if it helps I am using VS2012 and the Typescript plugin. 另外,如果有帮助,我正在使用VS2012和Typescript插件。

Thank you for the help! 感谢您的帮助! EDIT: Oh btw, I get the error (in chrome): Uncaught ReferenceError: t is not defined 编辑:哦,顺便说一句,我得到错误(chrome):未捕获的ReferenceError:t未定义

You need to include both scripts in your web page: 您需要在网页中同时包含两个脚本:

<script src="test.js"></script>
<script stc="main.js"></script>

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

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