feat(menu): idea to introduce generics and better types for components #7114
+51
−12
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.
Motivation
Better TS support which provides real type safety instead of just acting as
any
- mostly for safe usage of slotProps and emits payloads.Explanation
In a codebase this large it is near impossible to convert everything into composition API with TS, but we can define "secondary" components that will handle the types in a way that Vue can understand perfectly including generic types.
In this PR I have prepared it for the
Menu
component which uses the MenuItem interface for themodel
prop.This way of doing it should be a non-breaking change for all current usage as it would just infer the actual types of the items.
Caveats
Some prop types are very complicated, mostly the ones that extend large interfaces such as
ButtonHTMLAttributes
which the Vue compiler cannot handle when used inside of thedefineProps
macro. We would have to find a reasonable way around this. I go more into detail in this discussion: https://github.com/orgs/primefaces/discussions/3392