Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

336
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda