I'm experimenting with using a simple pattern for creating a type of 'value' object. To instantiate it, all properties should be specified in the constructor.
To avoid repeating the list of properties, I tried something like this:
interface Video {
id: number;
title: string;
}
class VideoCl implements Video {
constructor(properties: Video) {
for(const [k, v] of Object.entries(properties)) {
this[k] = v;
}
}
}
Unfortunately, Typescript will not allow this as it requires all the properties from the interface to exist on the class as well.
Is there a simple way to accomplish this that removes the need for repeating the properties?