Skip to Content
Learning TypeScript 2.x - Second Edition
book

Learning TypeScript 2.x - Second Edition

by Remo H. Jansen
April 2018
Beginner content levelBeginner
536 pages
13h 21m
English
Packt Publishing
Content preview from Learning TypeScript 2.x - Second Edition

Cross-file internal modules

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering TypeScript - Fourth Edition

Mastering TypeScript - Fourth Edition

Nathan Rozentals
Learning TypeScript

Learning TypeScript

Josh Goldberg
TypeScript for Beginners

TypeScript for Beginners

Bharath Thippireddy

Publisher Resources

ISBN: 9781788391474Supplemental Content