Vue 3 Composable with TypeScript
frontend
TypeScript
scaffolding
zen
Reusable Vue 3 composable following best practices and proper typing.
By emily_r
12/8/2025
Prompt
Vue 3 Composable with TypeScript
Create a Vue 3 composable called use[FeatureName] that handles [Functionality].
Requirements
- TypeScript - Use proper generic types
- Configuration options - Accept as parameter with default values
- Reactive refs - Return using
ref()andcomputed() - Cleanup logic - Implement in
onUnmountedif dealing with side effects - JSDoc comments - Document the composable and its parameters
- Error handling - Include try-catch blocks
- 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