ERROR: Invalid assignment target when using a type in ref
I am attempting to use drizzle orm and I have a table and models that look like
In a component for a form for
NewAccount
I have const form = ref<NewAccount>();
and when I try to map that using v-model in the html of the page like below.
I get the error:
I have tried using reactive
and make things work but no matter what I do it doesn't work. Even if I take the drizzle orm out of it like
the same error occurs.10 Replies
v-model requires a valid ref target. In your example,
form
is of type Ref<Test | undefined>
. Initializing a value would solve your problem:
ive done that too, same issue. Sorry should have stated that.
I changed it to:
with the same html as above and the same error comes up
Unfortunately I can't reproduce. That exact code works fine on my machine
hm okay I will see if I can get it to repro in a new project
although, you are running the project right? The error only shows up when trying to load the page itself
no errors show up in the intellisense or code itself
Yeah I have it working in the browser. No errors
Silly question, but have you tried restarting your dev server? Sometimes it gets messed up by certain project changes
Yes I have, I have created a stackblitz with the error occurring. Hopefully it can give you a better idea of the issue and possibly how to fix it.
https://stackblitz.com/edit/nuxt-starter-tygvdb?file=pages%2Findex.vue
Lucas
StackBlitz
Nuxt - Starter (forked) - StackBlitz
Create a new Nuxt project, module, layer or start from a theme with our collection of starters.
Oh, the issue is the question mark
form?.name
. I assume you had it there because originally you had a possibly undefined form.name
. After initializing your ref, I removed the question mark in my reproduction because form.name
always exists.ah. interesting. I could have sworn I tested removing those but I might have done it at a point where the object wasn't defined in the ref.
is there any particular reason why
wouldn't just default to the default object? So you don't have to re-specify all the properties etc.
either way thanks for the help!
I think that would be unexpected behavior for a lot of use cases
Default values would need to be generated somehow
I come from c# so passing in the types like that are a lot more common. Not a big deal, was just curious.