Description
Description:
When using defineEmits
with TypeScript type syntax and JSDoc comments, the emitted .d.ts
files discard all JSDoc documentation for emits while correctly preserving them for props. This significantly impacts developer experience as emit events lose their documentation in the generated type definitions.
Environment:
- Vue: 3.5.13
- vue-tsc: 5.8.3
- Vite: 6.3.4
- TypeScript: 5.8.3
Reproduction Steps:
- Create a component with documented emits:
<script setup lang="ts">
const emit = defineEmits<{
/**
* Triggered when operation succeeds
* @event confirm-success
*/
'confirm-success': [];
/**
* Triggered when operation fails
* @event confirm-error
* @param {Error} error - Detailed error information
*/
'confirm-error': [error: Error];
}>();
</script>
-
Run
vue-tsc --declaration --emitDeclarationOnly
-
Observe generated
.d.ts
file:
declare const __default: DefineComponent<{}, {}, {}, {}, {}, {}, {}, {
'confirm-success': [];
'confirm-error': [error: Error];
}>;
(Notice JSDoc is missing)
Proposed Solution
The solution would involve modifying vue-tsc
's type declaration emitter to preserve JSDoc comments for defineEmits
types, similar to how it already works for defineProps
.
Technical Implementation Expectations:
-
TypeScript AST Handling
The emitter should retain JSDoc nodes attached to emit event signatures in the TypeScript AST when generating.d.ts
files. -
Output Format
The generated declarations should mirror the input's documentation structure:declare const __default: DefineComponent<{}, {}, {}, {}, {}, {}, {}, { /** * Triggered when operation succeeds * @event confirm-success */ 'confirm-success': []; /** * Triggered when operation fails * @event confirm-error * @param {Error} error - Detailed error information */ 'confirm-error': [error: Error]; }>;
-
Consistency with Props
The behavior should match the existing JSDoc preservation fordefineProps
(which already works correctly).
Additional Notes
-
Priority Areas
The fix should prioritize:- Emits defined via type literals (
defineEmits<{...}>()
) - Both event descriptions (
/** comment */
) and@param
tags
- Emits defined via type literals (
-
Backward Compatibility
This change would be non-breaking, as it only adds documentation without affecting runtime behavior. -
Testing Suggestions
Test cases should verify:- Simple event descriptions
- Parameter-specific docs (
@param
) - Edge cases (union types, complex payloads)