-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
types: add RouteMeta interface to enable module augmentation #3385
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, can you make like the existing one at vuejs/router#407 and add a test?
@posva Although better than using plain It's better than nothing of course, since properties that have been declared will have their appropriate types. Therefore I'd propose leaving this "Record extension" up to the user. Then anyone who wants to is free to have their |
For Vue Router 3, that would be a breaking change, so we will have to keep |
I suppose that's the only way then. I'll update this as soon as I get back to my workspace. |
Sure! Let's see if existing tests pass and if the change is reasonable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last thing that needs to be done here is to export RouteMeta
from index.d.ts
and add a test at https://github.com/vuejs/vue-router/tree/dev/types/test 🙂
7c772e7
to
dece3e6
Compare
Close #3183
I added a
RouteMeta
interface to the type declarations to allow for stronger type safety using module augmentation.For example:
Would define
myRoute.meta.x
to be astring
. Non-existent properties will show an error.Unfortunately this is a (minor) breaking change. As far as I know this can't be avoided without sacrificing the added type-safety.
Users can manually revert to the original "
any
" behavior using an augmentation like this:I can't make this the default however, because it can't be overwritten using module augmentation.
In other words: the "
any
"-index type would stay "active", thus defeating the purpose of added type-safety.I hope this suggestion can be considered nonetheless.