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

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

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