How can I spread a class properties to the parent's super constructor?
ActionLog is a base class, it's instantiated in a method inside ActionRequestAccess
ActionRequestAccess.ts
export class ActionRequestAccess extends ActionLog {
constructor(public actionLog: ActionLog, public customerId: string) {
super(
actionLog.id, // Want to get rid of these assignments <<< and switch to something like: ...actionLog
actionLog.type,
actionLog.date,
actionLog.address,
actionLog.location
);
}
static override fromMap(map: any) {
if (!map) {
return null;
}
const baseMap = super.fromMap(map);
if (!baseMap) {
return null;
}
return new ActionRequestAccess(baseMap, map['customerId'] ?? null);
}
}
ActionLog.ts
import { ActionType } from '../../enums';
export class ActionLog {
constructor(
public id: string,
public type: ActionType,
public date: Date,
public address: string,
public location: string
) {}
static fromMap(map: any) {
if (!map) {
return null;
}
return new ActionLog(
map['id'] ?? null,
map['type'] ?? null,
map['date'] ?? null,
map['address'] ?? null,
map['location'] ?? null
);
}
}
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment