Cannot load class from file in TypeScript

后端 未结 1 1169
鱼传尺愫
鱼传尺愫 2021-01-19 01:19

I have a class which looks like this:

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


        
1条回答
  •  囚心锁ツ
    2021-01-19 01:58

    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( 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.

    0 讨论(0)
提交回复
热议问题