You could exclude undefined
using NonNullable utility:
const iconsMap: Record<NonNullable<status>, React.ReactSVGElement> = {
error: ErrorIcon,
success: SuccessIcon,
};
And formally you get the error not because there is no key undefined
, but because Record
has generic type constraint and accepts only string | number | symbol
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…