Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

223
Vistas
How to set types of dynamically acquired values in a class

I have a class and an interface with the class constructor receiving an instance of an object as the interface so I know all the keys but they are a lot of keys so I am trying not to do them manually and find a way to dynamically do it

import {APIGuild} from "discord-api-types"
class Main{
constructor(data: APIGuild){
for(const key in data){
this[key as keyof this] = data[key as keyof this]
}
}
}

The problem with this approach is that i am unable to gain the types for the class and using the implements keyword needs all the fields to be initialized which is a lot of work as APIGuild is a extended interface with 30+ fields so initializing them manually is.... bad plus many of the fields have dual possible types so if I assign an empty string to a field and turns out the field had to be null as it was not present may cause future problems

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda