April 2018
Beginner
536 pages
13h 21m
English
TypeScript allows us to declare internal modules across multiple files. If an internal module becomes too big, it can be divided into multiple files to increase its maintainability. If we take the preceding example, we could add more contents to the internal module named App by referencing it in a new file.
Let's create a new file, named validation.ts, and add the following code to it:
namespace App {
export namespace Validation {
export class UserValidator {
// ...
}
export class TalkValidator {
// ...
}
}
}
We can then access the namespace entities declared in both files by indicating the full namespace name:
const userModel = new App.Models.UserModel(); const talkModel = new App.Models.TalkModel(); const userValidator ...