Skip to content

docs: include example of @vue-generic directive #3219

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

Merged
merged 1 commit into from
Apr 11, 2025
Merged

Conversation

G-Rath
Copy link
Contributor

@G-Rath G-Rath commented Apr 10, 2025

Description of Problem

Currently the docs on generics are very light and very focused on how to define a generic component, rather than how to actually use said component and seems to assume that the generic value can always be inferred.

Proposed Solution

This adds an example of how to use generics in a template with the @vue-generic directive to explicitly tell TypeScript what type to use, for when the type cannot be inferred.

Currently I've used a very basic example based on my real-world usage, which does technically have a few assumptions but I think just having an @vue-generic example in the docs should greatly increase the chances of people figuring this out quickly.

I'm happy to expand on this further if people think that would be useful, such as adding an example of the component implementation to show why the type cannot be inferred or adding a contrasting example of a component not using the directive to avoid implying the directive should always be used

Additional Information

I personally spent a lot of time trying to figure this out which I ended up doing through a chain of something like a comment on an RFC that linked to another RFC which linked to a pull request which had been closed in favor of another, before eventually I found https://github.com/vuejs/language-tools/wiki/Directive-Comments (and that in turn lead me to learn about https://github.com/vuejs/language-tools/wiki/Vue-Compiler-Options which was very interesting too).

As far as I can tell, there's absolutely no documentation on the compiler options or directives.

Copy link

netlify bot commented Apr 10, 2025

Deploy Preview for vuejs ready!

Name Link
🔨 Latest commit 74ee2d2
🔍 Latest deploy log https://app.netlify.com/sites/vuejs/deploys/67f81e221b92f50008acb24e
😎 Deploy Preview https://deploy-preview-3219--vuejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@yyx990803 yyx990803 merged commit 2859a45 into vuejs:main Apr 11, 2025
5 checks passed
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

Successfully merging this pull request may close these issues.

2 participants