How does typescript define global variables?

for example, in the nodejs environment, there is a global variable global, which I defined directly when I didn"t use typescript before.
for example, redis instances and database instances are all defined as global instances. When it comes to typescript, we have no idea what to do with it.

Jun.10,2022

create a UUU.d.ts file (theoretically, of course, you can name it at will):

declare var  UUU:any

this creates a global variable UUU.

clipboard.png


I seem to have solved it myself.
I write the global object as a singleton pattern, and each module is introduced.

I found this answer before and felt dissatisfied: https://codeshelper.com/q/10...

.

there are better answers to add ~


Global variables should be avoided as much as possible. You can introduce instances using singleton mode, such as


    class DataMgr {
    static instance: DataMgr
    static getInstance() {
        if (!DataMgr.instance) {
            DataMgr.instance = new DataMgr()
        }
        return DataMgr.instance
    }

introduce this module when you want to use an instance, and DataMgr.getInstance () can

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3bb85-2bb02.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3bb85-2bb02.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?