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

321
Views
tipo 'typeof globalThis' no tiene firma de índice

Recibo este error cada vez que intento agregar una función al espacio de nombres global de nodejs global en un entorno de TypeScript.

El elemento tiene implícitamente un tipo 'cualquiera' porque el tipo 'typeof globalThis' no tiene firma de índice

declarando el espacio de nombres global

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

así que si pruebo esto

 global.signin = () => {}

devuelve un

El elemento tiene implícitamente un tipo 'cualquiera' porque el tipo 'typeof globalThis' no tiene firma de índice

over 4 years ago · Santiago Trujillo
7 answers
Answer question

0

Debe declarar una interfaz global declarada en global.d.ts de esta manera:

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

El vscode da sugerencias de código correctas

over 4 years ago · Santiago Trujillo Report

0

A continuación se muestra un ejemplo para Node v16

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

0

Yo también tuve el mismo problema. Se solucionó con el siguiente código.

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

0

simplemente declare la variable por palabra clave var . Me gusta esto:

 // 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;

ingrese la descripción de la imagen aquí

También puede declarar variables en archivos .d.ts .

ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo Report

0

Estaba teniendo un problema similar y descubrí que los tipos globales del nodo se cambiaron recientemente ; ahora puede anularlos haciendo:

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

Nota: esto no funcionará con let o const , debe usar var .

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

0

Debe usar la palabra clave var en declare global y eliminar namespace NodeJS { .
Me gusta esto:

 //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

O si no tiene importaciones en el archivo .d.ts :

 //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

en mi propio caso, no me di cuenta hasta más tarde de que el espacio de nombres global que declaré distinguía entre mayúsculas y minúsculas.

en lugar de esto. antes de que se editara mi pregunta, era el namespace NODEJS

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

se suponia que era esto

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

preste atención a NODEJS and NodeJS . Después de hacer estos cambios, mecanografiado estuvo bien con él y funcionó de la manera que esperaba.

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!