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

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