Bart van den Burg Bart van den Burg - 3 months ago 19
TypeScript Question

Typescript: How to organize an app

Here's something I can't wrap my head around. I have these typescript files:

// app.ts
import {SomethingService} from "./something";
new SomethingService().yay();


-

// something.ts
export class SomethingService {
yay() {
alert('yay?');
}
}


-

// index.html
<html>
<head>
<script src="require.js"></script>
<script src="app.js"></script>
</head>

<body>
</body>
</html>


I then compile the TS with:
tsc app.ts --module amd --outFile app.js


However, because of the import statement, app.ts is treated as a module and the actual code is never executed. The alert never pops up. How do I make sure the code in app.ts is executed?

Answer

So here it is you need to tell require.js to handle it.

<script data-main="app.js" src="require.js"></script>
Comments