Share data across windows with TypeScript

After porting our app to TypeScript I’m trying to share data between windows using that BackgroundController. I used to do that using the main window in native JavaScript.
I’ve added data members to BackgroundController.
Using them from two different windows except that it looks like the data members are optimized out of the BackgroundController for some reason. Worst it looks like I have four declaration of BackgroundController class in the compiled JS output one for each of my windows. So I’m guessing I’m in fact looking at four singletons :rofl:

Any tips on how to deal with that would be welcome.
Looking at the untouched SampleApp the BackgroundController is not exported and thus not actually used to share data between windows.

Confusingly you can’t use the BackgroundController ‘singleton’ from the TS SampleApp to communicate between windows.
You should really stick to the same method you used in JavaScript as explained there:

Looks like you can extend the Window object using TypeScript as explained there:

That interface trick from the StackOverflow answer did not work for me. I had to extend the Window class and cast it to the derived type to access the data member I added.