I figured that way I don’t need to write APIModule.getInstance in every file where I use it.
As to TS in general … at the risk of getting into opinion territory … I think TS is the wave of the future. It has been shooting up in popularity and “fixes” some of the “problems” with JS. I think any smart JS developer needs to learn TS.
I enjoy TS and find it satisfying to learn. However, I have heard some hardcore JS old-timers saying it is terrible for JS. Those same people are also not in favour of inheritance in JS, but I like it as I find it very intuitive to write, read and understand and gives me good control over my code. Although, I am sure you can do the same thing without it. You mentioned e.g. # which I read about recently somewhere.
Sure, I’ve seen patterns like that. It seems a little odd to me, some modules exporting class definitions and some exporting instances, but whatever.
However, I have heard some hardcore JS old-timers saying it is terrible for JS.
Pick any subject in coding and people will have strong opinions. Some people will purposely have strong attention to attract attention, sometimes for financial gain.
I just look at the steady growth of TS. There is plenty of data to show that TS keeps growing, like here. You will also find people complaining about it. You can also find people that don’t like ice cream.
I think that learning TS has improved how I code. When I write vanilla JS, I now write it better. I would say that unit testing did the same thing - it made me a better coder. #ymmv