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

326
Vistas
In JsDoc should `[key: string]: any;` allow me to use any key value property?

I am using npm pacakge jsonwebtoken, and the jwt.verify method. When I try to deconstruct the return value I get a intellisense error

Property 'userId' does not exist on type 'string | JwtPayload'.

My code looks like this.

({ userId } = jwt.verify(token, 'my_secret'));

When I look at the index.d.ts for jsonwebtoken it has this

export function verify(token: string, ...): JwtPayload | string;
export interface JwtPayload {
    [key: string]: any;
    iss?: string | undefined;
    ...
}

Shouldn't the [key: string]: any; allow me to create any key value property?

Why do i still get type errors and is there a way to get rid of them using jsdocs?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you use brackets to access the value then it will not complain.

Something like this

const payload = jwt.verify(token, 'my_secret'))

payload["userId"];
about 4 years ago · Juan Pablo Isaza 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