Say I have a class looking like below
class Model {
id: string;
_createdAt: string;
_updatedAt: string;
constructor(params: // currently I am doing Partial<Model> but I would like params to
// only contain the variables at the top excluding any methods/getters/setters){
this.id = params.id;
this._createdAt = params.createdAt;
this._updatedAt = params.updatedAt;
}
get createdAt{
return moment(this._createdAt);
}
get updatedAt{
return moment(this._updatedAt);
}
}
I would like to be able to construct a typescript type/interface of an object type that reflects the variables in the Model
. I am currently doing params: Partial<Model>
but this assumes that params
is going to contain all the properties of Model
class. However, I want only the variables to be the keys of the interface. Is there a way of doing this without having to define all properties of interface myself?