Index of every page on this site: llms.txt
All skills
jyasuu avatar

/vue-best-practices

@d3e2684
Run it yourself

Vue 3 and Vue.js best practices for TypeScript, vue-tsc, and Volar. This skill should be used when writing, reviewing, or refactoring Vue components to ensure correct typing patterns. Triggers on tasks involving Vue components, props extraction, wrapper components, template type checking, or Volar configuration.

  • 18 files
  • 39.7 KB
  • MIT
  • Updated 10 months ago
  • GitHub
Use this Skill: https://skilld.dev/gh/jyasuu/cheat-sheet/vue-best-practices

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

rulesvue-router-typed-params.md

≈629 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Vue Router useRoute Params Union Type Narrowing

Impact: MEDIUM - fixes "Property does not exist" errors with typed route params

With unplugin-vue-router typed routes, route.params becomes a union of ALL page param types. TypeScript cannot narrow Record<never, never> | { id: string } properly, causing "Property 'id' does not exist" errors even on the correct page.

Symptoms

  • "Property 'id' does not exist on type 'RouteParams'"
  • route.params.id shows as string | undefined everywhere
  • Union type of all route params instead of specific route
  • Type narrowing with if (route.name === 'users-id') doesn't work

Root Cause

unplugin-vue-router generates a union type of all possible route params. TypeScript's control flow analysis can't narrow this union based on route name checks.

Fix

Option 1: Pass route name to useRoute (recommended)

// pages/users/[id].vue
import { useRoute } from 'vue-router/auto'

// Specify the route path for proper typing
const route = useRoute('/users/[id]')

// Now properly typed as { id: string }
console.log(route.params.id)  // string, not string | undefined

Option 2: Type assertion with specific route

import { useRoute } from 'vue-router'
import type { RouteLocationNormalized } from 'vue-router/auto-routes'

const route = useRoute() as RouteLocationNormalized<'/users/[id]'>
route.params.id  // Properly typed

Option 3: Define route-specific param type

// In your page component
interface UserRouteParams {
  id: string
}

const route = useRoute()
const { id } = route.params as UserRouteParams

Required tsconfig Setting

Ensure moduleResolution: "bundler" for unplugin-vue-router:

{
  "compilerOptions": {
    "moduleResolution": "bundler"
  }
}

Caveat: Route Name Format

The route name matches the file path pattern:

  • pages/users/[id].vue → /users/[id]
  • pages/posts/[slug]/comments.vue → /posts/[slug]/comments

Reference

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at d3e2684. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 10 months ago
metadata
{
  "author": "hyf0",
  "version": "8.0.0"
}

README badge

README badge for jyasuu/cheat-sheet/vue-best-practices