admin管理员组

文章数量:1279120

I dont understand what i'm doing wrong. I've create a TypeScript project in VS2012, and created a file named "Vector.ts", in a sub-directory named "Physics":

// Module
module Physics {

    // Class
    export class Vector {
        constructor(public x: number) { }
    }

}

Also, I have the following app.ts file:

/// <reference path="Physics/Vector.ts" />

window.onload = () => {
    var vector = new Physics.Vector(6);
};

The project is successfully piled, but when i launch it, i get the following exception:

0x800a1391 - JavaScript runtime error: 'Physics' is undefined

I don't understand what am i doing wrong...

Thanks.

I dont understand what i'm doing wrong. I've create a TypeScript project in VS2012, and created a file named "Vector.ts", in a sub-directory named "Physics":

// Module
module Physics {

    // Class
    export class Vector {
        constructor(public x: number) { }
    }

}

Also, I have the following app.ts file:

/// <reference path="Physics/Vector.ts" />

window.onload = () => {
    var vector = new Physics.Vector(6);
};

The project is successfully piled, but when i launch it, i get the following exception:

0x800a1391 - JavaScript runtime error: 'Physics' is undefined

I don't understand what am i doing wrong...

Thanks.

Share Improve this question asked Mar 16, 2013 at 16:23 gipoufgipouf 1,2413 gold badges17 silver badges43 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

If you are using AMD style modules with a module loader such as Require.Js, you need an import statement. See Steve's accepted answer here: https://stackoverflow./a/14919495/1014822 Your code will look something like:

import Physics = module("Physics/Vector");

var vector = new Physics.Vector(6);

... and you won't need this: /// <reference path="Physics/Vector.ts" />

If you are not using a module loader, you just need to make sure you include your Vector.js output file somewhere in your html page, and make sure it loads before your app file. In this case, you use /// <reference path="Physics/Vector.ts" /> to tell TS where to find your module for intellisense etc. to work.

Just for pleteness, if you're using System then you'd use the import function:

System.import("Physics/Vector");

If you're doing this for Angular 2 then you'd want to do this before your bootstrap import

本文标签: javascriptTypeScriptModule is undefined at runtimeStack Overflow