Is it possible to have TypeScript infer the type of statusColor
as yellow
instead of Color
?
type Status = 'Invalid' | 'Progress' | 'Complete' | 'Error';
type Color= 'yellow' | 'red' | 'green' | 'blue';
const STATUS_TO_COLOR: Record<
Status,
Color
> = {
Invalid: 'yellow',
Progress: 'blue',
Complete: 'green',
Error: 'red',
} as const;
const statusColor = STATUS_TO_COLOR["Invalid"];
// ^ inferred as Color, can it be infered as "yellow"?
I have experimented with different approaches but none seem to work.