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