-
-
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
The type definition of Route seems to be partially wrong #3566
Comments
@posva Hello 👋 I'd like to add some information/context to this. Looking at the implementation of the stringifyQuery function I can see that it uses a function Since encodeURIComponent accepts numbers and booleans as well, what do you think about allowing these as well in the typing for Examplevm.$router.push({
name: 'someRoute',
query: { foo: 'foo', bar: 1, baz: true, qux: ['hello', 1, false] },
});
// Type 'number' is not assignable to type 'string'.
// Type 'boolean' is not assignable to type 'string'.
// Type '(string | number | false)[]' is not assignable to type 'string'. The result is: If you agree with this I would gladly work on a PR (add tests as well). This should cover most use cases without any changes to the current functionality. |
@mussinbenarbia You can give it a try if you want to accept The reason number and false are not assignable when doing a push is because there isn't any casting (like in v4) so the final type of the query ends up staying a number (non consistent if you reload the page). Therefore, without adding the forced casting (which could break a lot of users code and that's why it was added in vue router 4 only), it's better to keep |
Thank you for the feedback 👍 I'll give it a go. Still, I'd like if possible to clarify something. Isn't it still possible to allow Isn't that still an improvement? With the full understanding that no matter how Thank you! |
Version
3.5.1
Reproduction link
https://github.com/vuejs/vue-router/blob/dev/types/router.d.ts#L203
Steps to reproduce
None, just the source code seems to be wrong.
What is expected?
The type definition of Route#query should be
The current implementation cannot express this type of query
as it doesn't have any value and it is not converted to an array.
What is actually happening?
https://github.com/vuejs/vue-router/blob/dev/types/router.d.ts#L203
The type definition of Route#query is
The text was updated successfully, but these errors were encountered: