I have an interface that I only want to use within a namespace (internal module) and it should not be used outside the namespace.
Example interface:
namespace Test {
interface IInterface {
getId(): number;
getName(): string;
}
}
Unfortunately I get an error when I try to implement this interface within the same namespace if I don't export the interface (which I don't want to).
Implementing class:
namespace Test {
class Implementer implements IInterface {
private location: Location;
public getId(): number {
return 1;
}
public getName(): string {
return "implementer name";
}
}
}
Which gives: TS2304: Cannot find name 'IInterface'. in 'Implementer.ts'.
Notice the private member of type 'Location' which is also a new type/class defined by myself in the same namespace and that is the actual reason for using namespaces because the type 'Location' already exists in the global space.
Class with conflicting name if used outside namespace:
namespace Test {
class Location {
private name: string = null;
constructor(name: string) {
this.name = name;
}
}
}
Additionally: I'm not using any modules and I'm converting some types from JavaScript to TypeScript classes. Using the /// <reference path="IInterface.ts" /> helper doesn't work (and is not the problem here). I also don't want to introduce any module loader.
So how do I use my interface in the same namespace without exporting it?