vue-exhaustive-v-if
A v-if / v-else-if chain that tests the same value's .tag against two or more variants, doesn't end with v-else, and misses a variant of the value's enum type.
Why: a chain like that is a switch on an enum, written in the template. Any variant it doesn't name renders nothing, silently: the Failed state you forgot, or the variant someone adds next month. In the script, match or exhaustive-switch would catch it; in the template, this rule and <Match> do. Guide: Vue.
✕ Rejectedvue-exhaustive-v-if
vue
<script setup lang="ts">
import type { Enum } from "@evobug_com/safe-ts-std/enum";
type Payment = Enum<{ Pending: {}; Paid: { receipt: string }; Refunded: { reason: string } }>;
const props = defineProps<{ payment: Payment }>();
</script>
<template>
<p v-if="props.payment.tag === 'Pending'">Waiting for the bank</p>
<p v-else-if="props.payment.tag === 'Paid'">Receipt {{ props.payment.receipt }}</p>
</template>A refunded payment shows nothing.
✅ Accepted: <Match>, a slot per variant
✓ Accepted0 diagnostics
vue
<script setup lang="ts">
import type { Enum } from "@evobug_com/safe-ts-std/enum";
import { Match } from "@evobug_com/safe-ts-vue/match";
type Payment = Enum<{ Pending: {}; Paid: { receipt: string }; Refunded: { reason: string } }>;
const props = defineProps<{ payment: Payment }>();
</script>
<template>
<Match :value="props.payment">
<template #Pending>Waiting for the bank</template>
<template #Paid="{ receipt }">Receipt {{ receipt }}</template>
<template #Refunded="{ reason }">Refunded: {{ reason }}</template>
</Match>
</template>✅ Accepted: compute it with match, which won't compile with a variant missing
✓ Accepted0 diagnostics
vue
<script setup lang="ts">
import { computed } from "vue";
import { type Enum, match } from "@evobug_com/safe-ts-std/enum";
type Payment = Enum<{ Pending: {}; Paid: { receipt: string }; Refunded: { reason: string } }>;
const props = defineProps<{ payment: Payment }>();
const status = computed(() =>
match(props.payment, {
Pending: () => "Waiting for the bank",
Paid: ({ receipt }) => `Receipt ${receipt}`,
Refunded: ({ reason }) => `Refunded: ${reason}`,
}),
);
</script>
<template>
<p>{{ status }}</p>
</template>✅ Also accepted: a branch for every variant, when the branches are different elements and you'd rather not nest them in <Match>
✓ Accepted0 diagnostics
vue
<script setup lang="ts">
import { constructors, type Enum, is } from "@evobug_com/safe-ts-std/enum";
type Payment = Enum<{ Pending: {}; Paid: { receipt: string }; Refunded: { reason: string } }>;
const Payment = constructors<Payment>();
const props = defineProps<{ payment: Payment }>();
</script>
<template>
<p v-if="is(props.payment, Payment.Pending)">Waiting for the bank</p>
<p v-else-if="is(props.payment, Payment.Paid)">Receipt {{ props.payment.receipt }}</p>
<p v-else-if="is(props.payment, Payment.Refunded)">Refunded: {{ props.payment.reason }}</p>
</template>With the idiomatic rules off, the same chain on .tag (props.payment.tag === 'Paid') is checked the same way; with them on, prefer-is-over-tag asks for is.
The variants come from the value's declaration (defineProps<{ payment: Payment }>(), ref<Payment>(...), useTask(...)) and the Enum<{ ... }> it names, here or in the file it is imported from. When the checker can't see the type, any chain without v-else is reported.
A chain ending in v-else isn't reported, but a variant added later lands in the v-else without anyone being told: prefer a branch (or a <Match> slot) per variant. A single v-if on one variant (an error banner shown only for Failed) isn't a chain, and isn't reported.