5

I have a class which looks like this:

export module GameModule {
    export class Game {
        private boardContainer: HTMLElement;
        private board: number[][];

        constructor (container: HTMLDivElement) {
            this.boardContainer = container;
            this.board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];

            this.drawGrid();
        }

        drawGrid() {

        }
    }
}

and the main application:

import GameModule = module("./GameModule");

window.onload = () => {
    new GameModule.GameModule.Game(<HTMLDivElement> document.getElementById('content'));
};

But when I'm trying to compile the code, I'm getting errors:

>tsc --module amd app.tss
app.tss(1, 27): The name '"./GameModule"' does not exist in the current scope
app.tss(1, 27): A module cannot be aliased to a non-module type
app.tss(4, 8): Expected car, class, interface, or module

What's wrong with my code?

1
  • Hi @skayred! what is the name of the first file that you are trying to load the module? The name of first file must be "GameModule.ts." Can you verify this? Commented Oct 16, 2012 at 11:45

1 Answer 1

7

Your code compiles fine for me. Here is what I have:

GameModule.ts

export module GameModule {
    export class Game {
        private boardContainer: HTMLElement;
        private board: number[][];

        constructor (container: HTMLDivElement) {
            this.boardContainer = container;
            this.board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];

            this.drawGrid();
        }

        drawGrid() {

        }
    }
}

Main.ts

import GameModule = module("./GameModule");

window.onload = () => {
    new GameModule.GameModule.Game(<HTMLDivElement> document.getElementById('content'));
};

both in the same directory. When I compile it with

tsc --module amd Main.ts

the compiler reports no problems. Can you please check if you can compile exactly those two classes? Also, please post your complete code (if possible). From the error message I would assume that your module resides in another directory.

Sign up to request clarification or add additional context in comments.

5 Comments

My main class was names app.ts, and GameModule was in GameModule.ts. Was it issue in my naming?
@skayred I just noticed that you compiled app.tss . Was that a typo in your question? GameModule.ts is the correct name. You are using external modules, so the module import needs the relative name of the file that contains the module.
I've reproduce this bug again. Just create new VS2012 TypeScript project, change app.js content to my and create GameModule.ts. When you try to compile it, you get an error
Is it necessary to type GameModule twice? (As in new GameModule.GameModule.Game...)
@stepancheg It used to be. I'm unsure if that's still true with the latest version of the compiler but I guess so.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.