我有一个看起来像这样的课:
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() {
}
}
}
Run Code Online (Sandbox Code Playgroud)
和主要应用:
import GameModule = module("./GameModule");
window.onload = () => {
new GameModule.GameModule.Game(<HTMLDivElement> document.getElementById('content'));
};
Run Code Online (Sandbox Code Playgroud)
但是当我尝试编译代码时,我遇到了错误:
>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
Run Code Online (Sandbox Code Playgroud)
我的代码出了什么问题?
你的代码编译好我.这是我有的:
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() {
}
}
}
Run Code Online (Sandbox Code Playgroud)
Main.ts
import GameModule = module("./GameModule");
window.onload = () => {
new GameModule.GameModule.Game(<HTMLDivElement> document.getElementById('content'));
};
Run Code Online (Sandbox Code Playgroud)
两者都在同一目录中.当我用它编译它
tsc --module amd Main.ts
Run Code Online (Sandbox Code Playgroud)
编译器报告没有问题.你能检查一下你是否可以完全编译这两个类吗?另外,请发布完整的代码(如果可能).从错误消息我会假设您的模块驻留在另一个目录中.
| 归档时间: |
|
| 查看次数: |
3205 次 |
| 最近记录: |