In my file called checkoutTypes.ts
, I have defined some checkout types like this:
export type CheckoutInvoiceAddressSection = "InvoiceAddress";
export type CheckoutDeliveryAddressSection = "DeliveryAddress";
export type CheckoutDeliveryAndReviewSection = "DeliveryAndReview";
export type CheckoutSection = CheckoutInvoiceAddressSection | CheckoutDeliveryAddressSection | CheckoutDeliveryAndReviewSection;
In a function within a different file, I intend to utilize these types for matching cases in a switch()
statement:
import type { CheckoutInvoiceAddressSection, CheckoutDeliveryAddressSection, CheckoutDeliveryAndReviewSection, CheckoutSection } from "~/types/checkoutTypes";
interface Props {
identifier: CheckoutSection,
}
const props = defineProps<Props>();
const isSectionCompleted = computed(() => {
switch (props.identifier) {
case CheckoutInvoiceAddressSection:
return checkoutStore.getActiveSection !== CheckoutInvoiceAddressSection;
case CheckoutDeliveryAddressSection:
return checkoutStore.getActiveSection === CheckoutDeliveryAndReviewSection;
}
});
However, an error is appearing:
ReferenceError: CheckoutInvoiceAddressSection is not defined
. on the line with case CheckoutInvoiceAddressSection
.
Can type definitions not be used for comparison with a variable, or am I overlooking something else?