I have a TypeScript project. Basically I have a file called myId.ts:
export module MyModule {
export class MyId {
constructor() { ... }
public compareTo(other: MyId): number { ... }
public toString(): string { ... }
}
}
I have a tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"noImplicitAny": true,
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": false,
"module": "amd",
"outDir": "./out"
},
"files": [
"myId.ts"
]
}
I compile this thing using this command:
tsc --project .
Where the current directory contains the configuration file ad also the source file.
Well, when compiling everything is fine, I get out/myId.js:
define(["require", "exports"], function (require, exports) {
var MyModule;
(function (MyModule) {
var MyId = (function () {
function MyId() { ... }
MyId.prototype.compareTo = function (other) { ... };
MyId.prototype.toString = function () { ... };
})();
MyModule.MyId = MyId;
})(MyModule = exports.MyModule || (exports.MyModule = {}));
});
Problems referencing MyId
Well, I want to use this in a web page and call it from using JavaScript, so by following Require.JS guidelines, I create my web page:
<html>
<head>
<meta charset="UTF-8">
<title>EVT Example - Minimal</title>
<script src="./require.js" type="text/javascript" data-main="./myId"></script>
</head>
<body></body>
</html>
However, when I open the inspector (F12 tools) and try referencing MyModule.MyId, nothing can be found! How can I reference my type?
Everything loaded fine
The inspector told me that myId.js has been successfully loaded actually. So it is not a problem concerning the fact that Require.JS did not load the script.
What to do?