Skip to content
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

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

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

Conversation

andresespinosapc
Copy link

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.
@netlify
Copy link

netlify bot commented Aug 10, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants