Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(types): normalized Query can have undefined properties #1510

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

Open
andresespinosapc wants to merge 1 commit into vuejs:main
base: main
Choose a base branch
Loading
from andresespinosapc:main

Conversation

@andresespinosapc
Copy link

@andresespinosapc andresespinosapc commented Aug 10, 2022

When a query param is not present the query value is undefined, but the type is only string | null.

Here is the extract of code where I had this problem:

const route = useRoute();
const sortBy = ref(route.query.sort_by.toString())

I got Cannot read property 'toString' of undefined but the linter didn't give any errors.

When a query param is not present the query value is `undefined`, but the type is only `string | null`.
Here is the extract of code where I had this problem:
```
const route = useRoute();
const sortBy = ref(route.query.sort_by.toString())
```
I got `Cannot read property 'toString' of undefined` but the linter didn't give any errors.
Copy link

netlify bot commented Aug 10, 2022
edited
Loading

Deploy Preview for vue-router canceled.

Name Link
🔨 Latest commit 41cb329
🔍 Latest deploy log https://app.netlify.com/sites/vue-router/deploys/62f3d2f9467bdd0008557e03

@posva posva changed the title (削除) Fix LocationQuery type (削除ここまで) (追記) fix(types): Normalized Query can have undefined properties (追記ここまで) Aug 10, 2022
@posva posva changed the title (削除) fix(types): Normalized Query can have undefined properties (削除ここまで) (追記) fix(types): normalized Query can have undefined properties (追記ここまで) Aug 10, 2022
Copy link
Member

@posva posva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think this would indeed be better. Can you add a d-ts test and make sure others pass?

@posva posva added typescript Problem related to TS typings 💥 breaking change labels Apr 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@posva posva posva requested changes

Assignees

No one assigned

Labels

💥 breaking change typescript Problem related to TS typings

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /