javascripttypescriptrequirejsjs-amd

loading some typescript modules with requireJS


I have a problem with the connection of some typescript classes using RequireJs. In .ts files I use the modules syntax and AMD modules. And my main file is GameLoader.ts which returns a instance of the game. There for example I'm creaiting World instance:

import World = require('Resources/Scripts/Game/Entities/Game/World');
...
var world = new World(json.world.level, json.world.size, json.world.passMap);

and it works fine - World really required function

But at the same the same file (GameLoader.ts):

import Camera = require('Resources/Scripts/Game/Presentation/Camera/Camera');
...
var camera = new Camera();

Camera is empty object (instead of the function) Uncaught TypeError: Camera is not a function The file is loaded, but the debugger showed that its contents are not used - breakpoint within the function define doesn't work. But in World breakpoint is triggered prior to loading the main program.

Finding fault I tried to remove all things from Camera.ts. After removal of I called empty Camera in the same manner from another file (temp.ts):

import c = require('Resources/Scripts/Game/Presentation/Camera/Camera');
var cam = new c();
console.log(cam);

and it worked.

Ts-generated code by compiler (for Camera.js) in both cases looks the same. To call compiled files used the same way - by call RequireJs API.

Perhaps the problem is cyclical references that point to a file GameLoader? But my application built from classes that game (which instance exported from GameLoader) is used only in theirs instances.

Sorry for my bad English.


Solution

  • Perhaps the problem is cyclical references that point to a file GameLoader?

    Probably. Give the dependency view in atom-typescript a go https://github.com/TypeStrong/atom-typescript#dependency-view