switch type guarding with satisfies

This commit is contained in:
Marco Pedone 2026-02-02 10:53:43 +01:00
parent 2d0745f9ec
commit 217d6c7982
5 changed files with 13 additions and 11 deletions

View file

@ -203,7 +203,7 @@ export const IconMatrix = ({ type, ...rest }: IconMatrixProps) => {
case "thumbs-up": case "thumbs-up":
return <ThumbsUp {...rest} />; return <ThumbsUp {...rest} />;
default: default:
return <div>Icon not found</div>; throw new Error(`Invalid icon type: ${type satisfies never}`);
} }
}; };

View file

@ -204,7 +204,7 @@ function createStore(
} }
default: default:
return state; throw new Error(`Unhandled action type: ${action satisfies never}`);
} }
} }
@ -1291,7 +1291,7 @@ function FileUploadItemProgress(props: FileUploadItemProgressProps) {
); );
} }
default: case "linear":
return ( return (
<ItemProgressPrimitive <ItemProgressPrimitive
aria-labelledby={itemContext.nameId} aria-labelledby={itemContext.nameId}
@ -1315,6 +1315,8 @@ function FileUploadItemProgress(props: FileUploadItemProgressProps) {
/> />
</ItemProgressPrimitive> </ItemProgressPrimitive>
); );
default:
throw new Error(`Unknown variant: ${variant satisfies never}`);
} }
} }

View file

@ -158,6 +158,8 @@ const MapComp = ({
</CustomMarker> </CustomMarker>
</> </>
); );
default:
throw new Error(`Invalid marker type: ${markerType satisfies never}`);
} }
}; };

View file

@ -148,5 +148,7 @@ export const PaymentMethodToString = (type: PaymentType) => {
return "WeChat Pay"; return "WeChat Pay";
case "zip": case "zip":
return "Zip"; return "Zip";
default:
throw new Error(`Invalid payment type: ${type satisfies never}`);
} }
}; };

View file

@ -183,14 +183,10 @@ export const genMail = async ({ ...mail }: MailsTemplates) => {
title = "Invito al sito"; title = "Invito al sito";
break; break;
default: default:
mailComponent = null; throw new TRPCError({
break; code: "INTERNAL_SERVER_ERROR",
} message: `Tipo di email non valido: ${mail satisfies never}`,
if (mailComponent === null) { });
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Errore nella creazione dell'email",
});
} }
return { html: await render(mailComponent), title }; return { html: await render(mailComponent), title };