Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

322
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

Below is an example for Node v16

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

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 Denunciar

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 Denunciar

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda