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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With