node.jstypescriptmicroservices

type 'typeof globalThis' has no index signature


i get this error whenever i try to add a function to the global nodejs global namsepace in a TypeScript environment.

Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature

declaring the global namespace

declare global {
  namespace NodeJS {
    interface Global {
      signin(): string[]
    }
  }
}

so if i try this

global.signin = () => {}

it returns a

Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature


Solution

  • in my own case i didn't quite realize until later that the global namespace i declared was case sensitive.

    instead of this. before my question was edited it was namespace NODEJS

    declare global {
      namespace NODEJS {
        interface Global {
          signin(): string[]
        }
      }
    }
    

    it was supposed to be this

    declare global {
      namespace NodeJS {
        interface Global {
          signin(): string[]
        }
      }
    }
    

    pay attention to NODEJS and NodeJS. After i made these changes, typescript was cool with it and it work the way i expected it to.