Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.2K
Views
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

over 4 years ago · Santiago Trujillo
7 answers
Answer question

0

I too had the same issue. Fixed it by the below code.

declare global {
        function signin(): Promise<string[]>
}
over 4 years ago · Santiago Trujillo Report

0

You should declare a global declared as interface in global.d.ts like this:

export interface global {}
declare global {
  var signin: ()=>string[]
}

The vscode gives correct code hints

over 4 years ago · Santiago Trujillo Report

0

Below is an example for Node v16

// globals.d.ts
declare module globalThis {
    var signin: () => string[];
}
over 4 years ago · Santiago Trujillo Report

0

just declare variable by var keyword. like this:

// eslint-disable-next-line no-var
var hello = () => { console.log("hello world"); };
// eslint-disable-next-line no-var
var hi: () => number;

globalThis.hello();
globalThis.hi = () => 143;

enter image description here

You can declare variables in .d.ts files, too.

enter image description here

over 4 years ago · Santiago Trujillo Report

0

I was having a similar issue and I found that node's global typings were changed recently-ish; you can now override them by doing:

// global.d.ts
declare global {
    function someFunction(): string;
    var someVariable: string;
}

Note: this will not work with let or const you must use var.

// index.ts
global.someFunction = () => "some value";
global.someVariable = "some value";
over 4 years ago · Santiago Trujillo Report

0

You have to use the var keyword in declare global, and remove namespace NodeJS {.
Like this:

//globals.d.ts
import type { EventEmitter } from "events";
declare global {
    var myGlobal: EventEmitter;
}
/// <reference path="globals.d.ts" />
//index.ts
// reference needs to be at top of file
import { EventEmitter } from "events";
global.myGlobal = new EventEmitter();
global.myGlobal // EventEmitter type: EventEmitter
window.myGlobal // EventEmitter type: EventEmitter

Or if you don't have any imports in the .d.ts file:

//namedoesntmatter.d.ts
declare var a: string;
//index.ts
global.a = "Hello"
global.a //Hello type: string
window.a //Hello type: string
over 4 years ago · Santiago Trujillo Report

0

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.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!