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

324
Views
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 answers
Answer question

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