简体   繁体   中英

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. They are both in the same folder. Also if it helps I am using VS2012 and the Typescript plugin.

Thank you for the help! EDIT: Oh btw, I get the error (in chrome): Uncaught ReferenceError: t is not defined

You need to include both scripts in your web page:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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