Given the classes:
class EnumerationDTO {
designation: string;
id: number;
}
class ExecutionStatusDTO extends EnumerationDTO {
static readonly open: ExecutionStatusDTO = { id: 0, designation: 'Open' };
static readonly working: ExecutionStatusDTO = { id: 1, designation: 'Working' };
static readonly waiting: ExecutionStatusDTO = { id: 2, designation: 'Waiting' };
static readonly resting: ExecutionStatusDTO = { id: 3, designation: 'Resting' };
static readonly escalated: ExecutionStatusDTO = { id: 4, designation: 'Escalated' };
static readonly done: ExecutionStatusDTO = { id: 5, designation: 'Done' };
static readonly removed: ExecutionStatusDTO = { id: 6, designation: 'Removed' };
}
I need to count how many times each instance of ExecutionStatusDTO
appears in an array and save that count in an object of type:
type statusesCount: {
done: number;
escalated: number;
open: number;
removed: number;
resting: number;
waiting: number;
working: number;
}
But statusesCount
cannot be simply defined but mapped from ExecutionStatsDTO
Solution 1:
will give
Solution 2 (more convenient if using strictNullChecks):
will give