1

I am trying to do an SPA with Typescript and I would like to use a module constructed within multiple files. Here is the code I did:

salut.ts

module salut {
    export class salut1 {
        public Title = "salut1";
    }
}

salut2.ts

module salut {
    export class salut2 {
        public Title = "salut 2";
    }
}

MyApp.ts

/// <reference path="salut.ts" />
/// <reference path="salut2.ts" />

class MyApp {
    constructor() {
        var salut1 = new salut.salut1();
        var salut2 = new salut.salut2();
    }
}

window.onload = () => {
    var app = new MyApp();
};

Visual Studio Intellisense informs me that there is no error in the code, meanwhile, when I start the application, I have the following error in the console:

Uncaught ReferenceError: salut is not defined.

Thank you for any help.

1

1 Answer 1

1

You need to have <script> tags for salut.js and salut2.js above the tag for MyApp.js, or compile using --out so that there's only one .js file.

Sign up to request clarification or add additional context in comments.

1 Comment

This is working perfectly well, is it possible to use require js to load these files? In development I would use separated files while using merged file in production?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.