Skip to content
Vue 3.5+ · <script setup lang="ts"> · Templates checked as codeDocs by Gemini 4 Neon Extra

SAFE-TS for Vue.
Components checked whole. ​

A Vue template is executable code: JSON.parse inside it can throw, @click="save" silently drops a returned Result, and v-model="props.user.name" mutates the parent's state. SAFE-TS checks script and template together—the way Vue actually runs them.

23 rulesVue-specific checks on top of core
SFC + TSTemplates, scripts & composables
<Match>Compiles to a zero-cost v-if chain
SSR + RouterHydration checks & vue-router pack

Interactive Live Comparison

One component, written twice—running right here ​

Without SAFE-TS

Pick someone above to start a request.

With SAFE-TS (useTask + <Match>)

Pick someone above to start a request.

Both components run in your browser against a fake server: Ada takes 2 s, Grace takes 0.4 s, and Linus fails. Try picking Linus first, or Ada then Grace before Ada finishes. Read the full code & diagnostics behind this demo.

Vue Architecture

Four rules for bulletproof Vue components ​

01<template>

Templates are code ​

Every SAFE-TS rule runs in the template just like in <script setup>: unhandled throws, dropped Results, null, and reading optional props before guarding with v-if.

02defineModel()

Props are borrowed ​

Props belong to the parent. Read them; emit an event or use defineModel() to update them. State in <script setup> stays per-instance, never shared in plain <script>.

03useTask · <Match>

Async state is one value ​

Replace disagreeing loading, error, and data refs with one AsyncState. useTask aborts superseded runs automatically, and <Match> checks every slot exhaustively.

04@click

Handlers handle their errors ​

Vue invokes event handlers with nothing of yours around them and discards return values. Errors must be handled inside the handler where the UI can report them.

Side-by-Side · Checked with vue-tsc

Before and after ​

Every pair below is a real Vue SFC verified by cargo test and vue-tsc with strict templates.

Vue discards handler return values, so the error publish returns disappears silently.

✕ Rejectedmust-use-result
vue
<script setup lang="ts">
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, type Result } from "@evobug_com/safe-ts-std/result";

type PublishError = Enum<{ Empty: {}; TooLong: { max: number } }>;
const PublishError = constructors<PublishError>();

const props = defineProps<{ draft: string }>();

function publish(): Result<void, PublishError> {
  if (props.draft === "") return err(PublishError.Empty());
  if (props.draft.length > 280) return err(PublishError.TooLong({ max: 280 }));
  return undefined;
}
</script>

<template>
  <button @click="publish">Publish</button>
</template>

Model component state as one Enum (Editing, Rejected, Published) and render every state exhaustively with <Match>.

✓ Accepted0 diagnostics
vue
<script setup lang="ts">
import { shallowRef } from "vue";
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, isErr, type Result } from "@evobug_com/safe-ts-std/result";
import { Match } from "@evobug_com/safe-ts-vue/match";

type PublishError = Enum<{ Empty: {}; TooLong: { max: number } }>;
const PublishError = constructors<PublishError>();

type Publishing = Enum<{ Editing: {}; Rejected: { error: PublishError }; Published: {} }>;
const Publishing = constructors<Publishing>();

const props = defineProps<{ draft: string }>();
const emit = defineEmits<{ publish: [text: string] }>();
const state = shallowRef<Publishing>(Publishing.Editing());

function publish(): Result<void, PublishError> {
  if (props.draft === "") return err(PublishError.Empty());
  if (props.draft.length > 280) return err(PublishError.TooLong({ max: 280 }));
  emit("publish", props.draft);
  return undefined;
}

function onPublish(): void {
  const published = publish();
  state.value = isErr(published) ? Publishing.Rejected({ error: published.error }) : Publishing.Published();
}
</script>

<template>
  <Match :value="state">
    <template #Editing>
      <button @click="onPublish">Publish</button>
    </template>
    <template #Rejected="{ error }">
      <button @click="onPublish">Publish</button>
      <Match :value="error">
        <template #Empty>Write something first.</template>
        <template #TooLong="{ max }">Keep it under {{ max }} characters.</template>
      </Match>
    </template>
    <template #Published>Published.</template>
  </Match>
</template>

More in Errors in handlers.

Migration Cheatsheet

Common Vue idioms, rewritten cleanly ​

IdiomReported bySAFE-TS pattern
ref<HTMLElement | null>(null) for a template refno-nulluseElement("name") for always-rendered elements, useOptionalElement under v-if (Missing values)
ref<User>() filled in onMounted and shownvue-ref-without-valueuseTask + <Match> (Async state); local UI selections can still start empty (ref<Row | undefined>(undefined))
watch(settings, save, { deep: true })vue-deep-watch when reading a few fieldsWatch only the fields used; saving the whole object is accepted as-is
v-for over an object or Object.entries(x)vue-v-for-key for index keysKey by entry name: v-for="(count, name) in counts" :key="name"
defineProps<{ size?: Size }>() with exactOptionalPropertyTypesvue-tsc when passing undefinedProvide a destructured default (const { size = "md" } = defineProps<...>()), or type size?: Size | undefined

Tooling & Setup

Where it runs & how to install ​

Surface.vue SFCsComposables (.ts importing vue)
Vite dev server & build✅✅
safe-ts check src/main.ts✅ follows .vue imports✅
Editor (safe-ts lsp)✅✅
Editor & CI (oxlint plugin)✅ script + template✅
Type checkingvue-tsctsc

Server-side rendering adds two more rules (SSR), and vue-router ships its own feature pack (vue-router).

sh
npm install -D @evobug_com/safe-ts-transform @evobug_com/oxlint-plugin-safe-ts oxlint
npm install @evobug_com/safe-ts-std @evobug_com/safe-ts-vue
ts
import { safeTs } from "@evobug_com/safe-ts-transform";
import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";

// safeTs before vue: checks each component and rewrites <Match> before Vue compiles it.
export default defineConfig({ plugins: [safeTs({ check: "error" }), vue()] });
sh
git clone https://git.evobug.com/Evobug/Safe-Ts.git
cd Safe-Ts
npm install
npm run build
npm run dev -w examples/vue

Full tsconfig, oxlint, and prelude setup is in Vue Setup.

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra