the Ref type seem to unwrap deeply nested ref when it should not #12219
-
I'm encountering a TypeScript error when trying to use a Ref inside an array of objects. In my code, r should be a Ref, but it's being treated as a boolean. Here's the simplified code:
Error: Types of property 'r' are incompatible. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
It's bascause Vue's type system automatically infers and unwraps nested ref types. So there's no need to explicitly decalre the variable's type. Vue's type system is smart enough to infer the correct type based on the value passed to ref() Just simply write like this: const foo = ref<Foo>([]); It works, right ? |
Beta Was this translation helpful? Give feedback.
-
I’ve encountered a similar issue. A |
Beta Was this translation helpful? Give feedback.
-
Thank you |
Beta Was this translation helpful? Give feedback.
I’ve encountered a similar issue. A
ref
within aref
gets automatically unwrapped. This seems to be a confusing feature. As a solution, you can change the outerref
to ashallowRef
, so the inner ref won’t be automatically unwrapped.