-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
shallowRef
value incompatible with parameter of the same type
#10368
Comments
Due to the fact that generics require types to be explicitly determined at their usage, unexpected types may arise within functions. It is suggested to use the following approach: interface Base {
start: number
}
export function useComposable<T extends Base>(callback: (value: T) => void) {
const myRef: ShallowRef<T | null> = shallowRef(null)
if (myRef.value) {
callback(myRef.value)
}
} |
@Alfred-Skyblue do you have an example? |
@Alfred-Skyblue this example is for In my original reproduction case, changing Also the answer you've linked, was written before version |
I'm just giving a similar example. Due to the uncertainty of generics, we can't guarantee that it returns the passed generic type. |
Ok seems a bit odd - then why even offer this in the first place, if the recommendation is to cast 😅 But OK understood. I can update my code. Thanks 🙏 |
Vue version
3.3.12
Link to minimal reproduction
https://stackblitz.com/edit/vue3-vite-starter-nvhwqh?file=src%2Fissue.ts
Steps to reproduce
Use
3.3.12
Create a shallowRef with a generic type that extends an interface
T extends Base
The value of shallowRef is incompatible as a parameter to functions that accept
T
Reproduce the same case with
3.3.11
There is no issue
ℹ️ This is still an issue on
3.4.x
also.What is expected?
Here I would expect the value of my shallowRef
T
to be compatible withT
.What is actually happening?
Argument of type 'Base | T' is not assignable to parameter of type 'T'.
System Info
Any additional comments?
Likely related to this?
#9839
And wondering if it's not related to this comment specifically?
But then how should I correct do what I've described? ☝️
The text was updated successfully, but these errors were encountered: