Vue 3 Composable with TypeScript

frontend
TypeScript
scaffolding
zen
Remix

Reusable Vue 3 composable following best practices and proper typing.

12/8/2025

Prompt

Vue 3 Composable with TypeScript

Create a Vue 3 composable called use[FeatureName] that handles [Functionality].

Requirements

  1. TypeScript - Use proper generic types
  2. Configuration options - Accept as parameter with default values
  3. Reactive refs - Return using ref() and computed()
  4. Cleanup logic - Implement in onUnmounted if dealing with side effects
  5. JSDoc comments - Document the composable and its parameters
  6. Error handling - Include try-catch blocks
  7. Tree-shakeable - Follow best practices for tree-shaking

Example Structure

import { ref, computed, onUnmounted } from 'vue';

export function use[FeatureName](options?) {
  const data = ref(null);
  const loading = ref(false);
  const error = ref(null);
  
  const refetch = () => {
    // refetch logic
  };
  
  onUnmounted(() => {
    // cleanup
  });
  
  return { data, loading, error, refetch };
}

Tags

vue
composables
typescript
vue3

Tested Models

gpt-4
claude-3-sonnet

Comments (0)

Sign in to leave a comment

Sign In
Vue 3 Composable with TypeScript | vibeprompt.directory