docs: include example of @vue-generic
directive
#3219
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.