Skip to content

vue-tsc doesn't preserve JSDoc comments for emits in generated .d.ts files #5348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
happyyangyuan opened this issue May 4, 2025 · 0 comments

Comments

@happyyangyuan
Copy link

happyyangyuan commented May 4, 2025

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:

  1. 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>
  1. Run vue-tsc --declaration --emitDeclarationOnly

  2. 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:

  1. TypeScript AST Handling
    The emitter should retain JSDoc nodes attached to emit event signatures in the TypeScript AST when generating .d.ts files.

  2. 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];
    }>;
  3. Consistency with Props
    The behavior should match the existing JSDoc preservation for defineProps (which already works correctly).


Additional Notes

  1. Priority Areas
    The fix should prioritize:

    • Emits defined via type literals (defineEmits<{...}>())
    • Both event descriptions (/** comment */) and @param tags
  2. Backward Compatibility
    This change would be non-breaking, as it only adds documentation without affecting runtime behavior.

  3. Testing Suggestions
    Test cases should verify:

    • Simple event descriptions
    • Parameter-specific docs (@param)
    • Edge cases (union types, complex payloads)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant