In my typings file, I have a plethora of deeply nested namespaces that were generated from various C# classes. Currently, this typings file is being utilized by other code that relies on internal modules. Although I am in the process of phasing out that code, it will take some time and there are certain pieces of code that need to be executed immediately.
The structure of the typings file is as follows:
declare namespace Thing.Stuff.WhosOnFirst.WhatsOnSecond {
export interface IDontKnowsOnThird {
... numerous interfaces without any classes, resulting in no JavaScript output.
}
}
Naturally, working with these deeply nested namespaces can be quite cumbersome:
public findShortStop(
thirdBase: Thing.Stuff.WhosOnFirst.WhatsOnSecond.IDontKnowsOnThird,
pitcher: Thing.Stuff.WhosOnFirst.WhatsOnSecond.Tomorrow
) {
...
}
To simplify the usage, I aim to employ import statements as aliases. Interestingly enough, I have often been able to utilize statements like the following due to the existence of "Thing" within my workspace:
import Stuff = Thing.Stuff;
However, when attempting to do the same for the deeply nested classes, I encountered an issue:
import WhatsOnSecond = Thing.Stuff.WhosOnFirst.WhatsOnSecond;
let baseman: WhatsOnSecond.IDontKnowsOnThird = {};
The resultant JavaScript code looks like this:
WhatsOnSecond = Thing.Stuff.WhosOnFirst.WhatsOnSecond;
var baseman = {};
Unfortunately, this triggers an error message in the console:
Uncaught (in promise) Error: (SystemJS) TypeError: Cannot read property 'WhosOnFirst' of undefined
at execute (http://localhost/Scripts/Shared/utils.js?v=180907165808:10:59)
Even though "Thing" exists, "Stuff" does not. Thus, creating an alias for Stuff results in valid but nonsensical code. On the contrary, accessing further-nested properties fails as trying to access properties of "undefined" leads to a JavaScript error which halts script execution.
My question is: How can I establish import aliases to ease referencing deeply-nested namespaces, so I do not have to type out the entire namespace whenever I refer to an interface?
The tedious task of typing out lengthy namespace chains every time I use an interface quickly becomes tiresome.