TypeScript. Enum/Union как ключ
export enum DetailStatus {
IN_WAREHOUSE = 'in_warehouse',
IN_SERVER = 'in_server',
WRITTEN_OFF = 'written_off',
RESERVED = 'reserved',
REPAIR = 'under_repair',
LABORATORY = 'in_laboratory',
BROKEN = 'broken',
}
export type DetailType = 'cpu' | 'ram' | 'pci' | 'storage';
export type DetailCountInfo = {
[type in DetailType]: {
[status in DetailStatus]: number;
};
};
Эквивалентно:
type DetailCountInfo = {
cpu: {
in_warehouse: number;
in_server: number;
written_off: number;
reserved: number;
under_repair: number;
in_laboratory: number;
broken: number;
};
ram: {
in_warehouse: number;
in_server: number;
... 4 more ...;
broken: number;
};
pci: {
...;
};
storage: {
...;
};
};