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

View file

@ -158,6 +158,8 @@ const MapComp = ({
</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";
case "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";
break;
default:
mailComponent = null;
break;
}
if (mailComponent === null) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Errore nella creazione dell'email",
});
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: `Tipo di email non valido: ${mail satisfies never}`,
});
}
return { html: await render(mailComponent), title };