Skip to content

Can't Find Classes in Another File but Under the same Namespace

Manabu Tokunaga edited this page Mar 16, 2017 · 2 revisions

Problem

You have split your sources into more than one files under the same namespace and the first file does not pick up the class or value defined in another file under the same namespace.

Solution

You should export any symbols that you need to share with other files. This is counter-intuitive because in C# or JavaScript package they will share anything under the same named space. See export class usage in File 2.

File 1: MySpace.ts

namespace TheSpace {
    
    class myStuff {
        name = "my stuff";
        static print() {
            let t = new TheirSpace();
            let h = herName;
            console.log(`Found ${t.name} in theirspace and ${h} in her space`);
        }
    }

    myStuff.print();
}

File 2: TheirSpace.ts

namespace TheSpace {
    export class TheirSpace {
        name = "their stuff";
    }
}