question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vetur to Volar => undefined problem in modelValue

See original GitHub issue

Hello, when I changed Vetur to Volar, all my q-input, q-select… generates these errors :

Cannot assign type 'string | undefined 'to type' string | number'.
Cannot assign type 'string | undefined 'to type' string | number | any [] '.

but normal (html) inputs no.

the cause is the declaration file it does not contain undefined

modelValue: string | number;

I am using DTOs which may have null or undefined values, DTOs are generated with OpenApi Generator, and any fields not required are converted to string | undefined. so either I have to change the q-input by input, or else create intermediate DTOs and do a DTO <-> [DTO without undefined] mapping, which will add complexity for nothing and a loss of performance

OR add undefined to all modelValue on Quasar declaration file ? like this : modelValue: string | number | undefined;

if you have any solutions or tips for this kind of problem, i will be very grateful to you

example :

-------> script

interface TestDTO
{
  a: string | undefined;
  b: string;
}

const entry : Ref<TestDTO> = ref(<TestDTO>{});

-----> in template :

** with Volar 
<q-input v-model="entry.a" />   // Volar cast error
<q-input v-model="entry.b" />  // OK 

<input v-model="entry.a" />   // OK
** with Vetur 
<q-input v-model="entry.a" />   // OK
<q-input v-model="entry.b" />  // OK 

<input v-model="entry.a" />   // OK

even by forcing the values, still the same problem with Volar

const entry : Ref<TestDTO> = ref(<TestDTO>{a: '',  b: ''});

Platform (please complete the following information): Quasar Version: 2.1.4

thank you for your precious time…

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
rstoenescucommented, Oct 20, 2021

Made other improvements as well.

1reaction
ItsClemicommented, Oct 20, 2021

Awesome!

Does Volar require the modelValue property in the type definitions?

Because when used with tsx, ts also requires this property which then clashes with v-model usage. Therefore we currently replace all required modelValue: properties with optional ones via patch files.

Eg.:

@@ -1362,7 +1362,7 @@ export interface QBtnDropdownProps {
   /**
    * Controls Menu show/hidden state; Either use this property (along with a listener for 'update:modelValue' event) OR use v-model directive
    */
-  modelValue: boolean;
+  modelValue?: boolean;
   /**
    * Size in CSS units, including unit name or standard size name (xs|sm|md|lg|xl)
    */

Thanks 🥳

Read more comments on GitHub >

github_iconTop Results From Across the Web

Detected Vetur enabled. Consider disabling Vetur and use ...
TLDR: uninstall Vetur and keep Volar (official recommended extension). Volar is the official VScode plugin to use since few months, ...
Read more >
@volar/vue-typescript | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
CHANGELOG.en-US.md · element-plus/element-plus - Gitee
Dev add global component types for volar (#3624 by @sxzz); Utils extract color to utils & fix ... Add tags and attributes completions...
Read more >
Source - GitHub
Fix `v-model` usage in Vue 3 where default prop name is `modelValue` ... See https://github.com/vuejs/vetur/issues/1083#issuecomment-464877917 for the demo.
Read more >
CHANGELOG.md · master · mirrors / vuejs / vetur · GitCode
Export all component for volar together. ... Fix v-model usage in Vue 3 where default prop name is modelValue instead of value ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found