Share an object instance across modules in typescript

I’m operating a bot on Wikipedia using npm mwbot, and planning to migrate to npm mwn. This is because you need a “token” to edit pages on Wikipedia, and this can expire after a while so you need to prepare your own countermeasures against this if you use mwbot, but it seems like mwn handles this issue on its own.

When you use mwn, you first need to initialize a bot instance as documented on the turotial:

const bot = await mwn.init(myUserInfo);

Then your token is stored in the bot instance and you can for example edit a page using:

const result = await bot.edit('Page title', () => {text: 'text'});

So, basically you want to share the initialized bot instance across modules. I believe it’d be easiest to declare a global variable like so:

// bot.js (main script)
const {mwn} = require('mwn');
const {my} = require('./modules/my');

(async() => {
    global.mw = await mwn.init(my.userinfo);
    const {t} = require('./modules/test');
    t();
})();
// modules/test.js
/* global mw */

exports.t = async () => {
    const content = await mw.read('Main page');
    console.log(content);
    return content;
};

I’m currently using JavaScript, but will hopefully migrate to TypeScript (although I’m new to it) because I feel like it’d be useful in developing some of my modules. But I’m stuck with how I should use the initialized bot instance across modules in TypeScript.

-+-- dist (<= where ts files are compiled into)
 +-- src
     +-- types
         +-- global.d.ts
     +-- bot.ts
     +-- my.ts
// bot.ts
import {mwn} from 'mwn';
import {my} from './my';
(async() => {
    global.mw = await mwn.init(my.userinfo);
})();

// global.d.ts
import {mwn} from 'mwn';

declare global {
    // eslint-disable-next-line no-var
    var mw: mwn;
}

This doesn’t work and returns “Element implicitly has an ‘any’ type because type ‘typeof globalThis’ has no index signature. (at mw in global.mw)”.

This is probably a naive question but any help would be appreciated.