-
Notifications
You must be signed in to change notification settings - Fork 75
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
Possible key
type mismatch
#315
Comments
ATM I'm working around this by explicitly returning |
I think if you defined your original const differently it would pass the checks: const maybeUndefined = ref<string>('')
// or as null without even declaring a type
const maybeUndefined = ref(null) But you're saying you should be able to define an "empty" ref, meaning it should be able to be const user = ref()
const { data: projects } = useSWRV(() => user.value && '/api/projects?uid=' + user.value.id, fetch)
const user = ref<string>('')
const { data: projects } = useSWRV(() => user.value && '/api/projects?uid=' + user.value.id, fetch) |
I'm more concerned about breaking the interface for |
Yes, I agree - this could be a breaking change. Speaking of which, I would consider switching the behaviour from const id = ref<number>() // undefined
const { data } = useSWRV(
() => id.value && `/posts/${id.value}`,
fetch
)
id.value = 0 // not undefined, but still falsy In this case, the fetch would not be triggered, however a post (a user, an object) with an However, maybe in this case, leaving the developer to explicitly return |
In JavaScript, |
I understand, yes. So in my example above you would suggest that |
Correct, because they both evaluate as falsy. |
Is this a desired behaviour? It would seem common to have an object on the backend with an |
Instead of thinking about something with an If I have a starting value of an iterator as I see your use-case; however, I would think if you know you're dealing with falsy values coming from your data structure you would use something you know that cannot equate to falsy as your dependent fetcher key. |
Fair enough. Should we consider implementing changes regarding my initial message in this issue - to include |
I'm still wondering if adding |
According to docs something like this should be possible:
However, the following code triggers a TS type mismatch warning
Warning reads:
Upon further digging the issue seems to be in type declaration for
keyFunction
It would seem that amending
keyType
towould fix the issue.
However I'm not sure if this doesn't break something down the line :)
The text was updated successfully, but these errors were encountered: