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

140
Views
Using JSDoc to set an index signature on an ES6 Class

In Typescript, you'd just do this:

class Test {
  [key: string]: whatever
}

Which allows you to access computed property names like so...

class Test {
  getProp(key) {
    return this[key]
  }
}

... without receiving Element implicitly has an 'any' type because type 'Test' has no index signature.

I can't figure out how to accomplish the equivalent with JSDoc. Anyone had any luck with this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For a single method, it's possible to do this with the @this tag:

class Test {
    /**
     * @this {{[k: string]: string}}
     * @param {string} key
     */
    getProp(key) {
        return this[key]
    }
}

Doing it for the entire class isn't yet supported. There is an open feature request (TypeScript#48096) which is currently in the TS 4.7.1 milestone. However, given the Needs Proposal label, somebody needs to come up with a proposed JSDoc tag + syntax, or it will likely end up being pushed off that milestone.

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!