I need help figuring out how to address a TypeScript error in my code. Here's the scenario:
export type status = 'success' | 'error' | undefined;
There is an object that maps to different icons based on the status.
const iconsMap: Record<status, React.ReactSVGElement> = {
error: ErrorIcon,
success: SuccessIcon,
};
The issue arises because there is no key for undefined
in the iconsMap, leading to a TypeScript error message:
Type 'string | undefined' does not satisfy the constraint 'string | number | symbol'. Type 'undefined' is not assignable to type 'string | number | symbol'.
Can anyone provide guidance on how to resolve this error?