How does typescript node declare global variables?

recently I"ve been learning that ts, doesn"t quite understand this part of global variables. For example, such an expression in the original node

global.sql = require("./tools/mysql").sql;

this allows you to define a global variable.
and how should this sql global variable be defined in ts?

Apr.07,2021

first of all, TypeScript discourages writing global variables and encourages the use of modular systems. Therefore, TS does not and will not have a convenient way to write global.
secondly, the module system of TypeScript has been replaced with import / export of the ES standard, and should not continue to use require .

then answer your question. The way to define global variables is

  1. write

    in sql.ts
      

    what if you are in the rendering process?

Menu