Skip to content
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

Typescript error on Switch and Listbox v-model in VSCode using Volar #368

Closed
ananni13 opened this issue Apr 15, 2021 · 5 comments
Closed

Comments

@ananni13
Copy link
Contributor

ananni13 commented Apr 15, 2021

What package within Headless UI are you using?

@headlessui/vue

What version of that package are you using?

1.1.0

What browser are you using?

Chrome

Reproduction repository

https://github.com/ananni13/test-headlessui

So this is just an IDE issue, in VSCode (using Volar), v-model on the Switch component shows this error:

ts-error

@pingustar
Copy link

pingustar commented Apr 27, 2021

I have the same issue and it is causing my build to fail because of tsc.

@pingustar
Copy link

@RobinMalfait

Would you like a PR to fix this?

I think this should fix it:

modelValue: { type: [Object, Boolean], default: null },

change this:

modelValue: { type: [Object, Boolean], default: null },

to:

modelValue: { type: Boolean, default: false },

@RobinMalfait
Copy link
Member

@pingustar that would be awesome, can you create a PR against the develop branch?

@ananni13
Copy link
Contributor Author

ananni13 commented Apr 27, 2021

I also tried Listbox and RadioGroup (I think those are the only other components that use v-model so far).
I updated the demo repository as well, copying the examples directly from the docs.

Listbox shows the same type of error as Switch:
listbox

And there's also a problem with ListboxOption value prop:
option

RadioGroup and RadioGroupOption show no errors, v-model is recognized as modelValue?: unknown and value as value?: unknown.

@ananni13 ananni13 changed the title Typescript error on Switch v-model in VSCode using Volar Typescript error on Switch and Listbox v-model in VSCode using Volar Apr 27, 2021
@ananni13
Copy link
Contributor Author

Looks like the difference between Listbox and RadioGroup is here:

export let RadioGroup = defineComponent({
name: 'RadioGroup',
emits: ['update:modelValue'],
props: {
as: { type: [Object, String], default: 'div' },
disabled: { type: [Boolean], default: false },
modelValue: { type: [Object, String, Number, Boolean] },
},

export let RadioGroupOption = defineComponent({
name: 'RadioGroupOption',
props: {
as: { type: [Object, String], default: 'div' },
value: { type: [Object, String, Number, Boolean] },
disabled: { type: Boolean, default: false },
class: { type: [String, Function], required: false },
className: { type: [String, Function], required: false },
},

export let Listbox = defineComponent({
name: 'Listbox',
emits: ['update:modelValue'],
props: {
as: { type: [Object, String], default: 'template' },
disabled: { type: [Boolean], default: false },
modelValue: { type: [Object, String, Number, Boolean], default: null },
},

export let ListboxOption = defineComponent({
name: 'ListboxOption',
props: {
as: { type: [Object, String], default: 'li' },
value: { type: [Object, String], default: null },
disabled: { type: Boolean, default: false },
class: { type: [String, Function], required: false },
className: { type: [String, Function], required: false },
},

RadioGroup doesn't have a default for modelValue (and value), so in the generated declaration file they are typed as unknown instead of null.

RobinMalfait added a commit that referenced this issue Apr 28, 2021
Fixes: #368
Fixes: #457
Closes: #459
RobinMalfait added a commit that referenced this issue Apr 28, 2021
Fixes: #368
Fixes: #457
Closes: #459
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants