0
votes

I'm using TypeScript internal modules to structure my code into logical blocks. (much like a C# assembly or a Java jar).

When doing so, the TypeScript classes within such an internal module are split across different files (one file per class). However, referencing classes inside this module only works when those classes are exported.

Naturally, I'd like to keep some of those classes internal to my module. For example, suppose I'd like to keep both of these classes internal.

/// Bicycle.ts
module Sample {

    class Bicycle {
    }
}

/// Mountainbike.ts
/// <reference path="Bicycle.ts" />
module Sample {

    class Mountainbike extends Bicyle {
    }
}

Using visual studio 2013, this only compiles when putting an export on the Bicycle class. When I put both classes in a single file, everything works fine. Am I missing something here?

Thanks for your time, Koen

1

1 Answers

0
votes

There isn't a concept of "module internal" in TypeScript. Things are either visible from outside your immediate module declaration (export) or not (no export).

If you have some set of types you'd like to be left alone, you can structure your code so it's clearer to consumers which types should not be used:

module Sample {
    export module Internal {
        export class Bicycle { }
    }
}

/* Somewhere else */
module Sample {
    export class MountainBike extends Internal.Bicycle {

    }
}

Note that since modules can always be re-opened, this approach is just as 'safe' as it would be if there were some concept of module-internal. You can think of this as analogous to how there isn't a concept of a "public namespace" or "private namespace" in C#.