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

166
Visualizações
Specify type as instance of a class?

I have a very specific case where I import an object containing class declarations, and I use it to create an instance as a property of another class. With class properties, I need to define a type, but when I do, the assigned type is typeof <class> instead of an instance of it (1. below).

I can get around this by assigning the prototype of the class as the type like in 2., but it feels too convoluted. Is a way to declare that the type is an instanceof the class, similar to how a type can be a typeof a class?

1. Setting type directly doesn't work

typeof foo

2. Using the class's prototype object works enter image description here

3. Works automatically for declared variables foo instance

4. Also works if the class isn't an object property enter image description here

Given that 3. works, I think the solution could be in how @type is declared, but in 4. foo's type after being imported is properly set as a class, instead of typeof foo when it's a property.

I'd appreciate the help of anyone who knows enough about JSDoc in explaining what's actually happening here, and how I can set the @type properly.

Thank you in advance.

about 4 years ago · Juan Pablo Isaza
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