I'm encountering an issue where imports in one section of my hierarchy appear to generate completely new types - they are not part of the same class and do not share static variables.
Let's say I have a folder structure like this:
app/
|-main.ts
|-static/
|-|-StaticClass.ts
|-consumer/
|_|-Consumer.ts
otherConsumer/
|-OtherConsumer.ts
Main.ts:
import { StaticClass } from './static/StaticClass';
import { Consumer } from './Consumer';
import { OtherConsumer } from '../otherConsumer/OtherConsumer';
export class Main {
constructor() {
StaticClass.INIT();
new Consumer();
new OtherConsumer();
}
}
StaticClass.ts:
export class StaticClass {
public static A:string;
public static INIT():void {
StaticClass.A = "Hello";
}
}
Consumer.ts:
import { StaticClass } from './static/StaticClass';
export class Consumer {
constructor() {
alert (StaticClass.A);
}
}
And let's assume OtherConsumer.ts does the same thing as Consumer.ts.
When Main is executed, Consumer displays "Hello" and OtherConsumer displays "undefined".
If the "static/" directory is moved up one level in the hierarchy to be a sibling of "app" and "otherConsumer" (and all import paths adjusted accordingly), then both consumers display "Hello". They also show "Hello" if the otherConsumer directory is relocated within the app directory.
What could be causing this? Is OtherConsumer placed in a different 'require' namespace because it is located outside the main application directory?