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

TS2322 when using multiple checkboxes, bound to the same array #4321

Closed
antony-k1208 opened this issue Aug 12, 2021 · 5 comments
Closed

TS2322 when using multiple checkboxes, bound to the same array #4321

antony-k1208 opened this issue Aug 12, 2021 · 5 comments

Comments

@antony-k1208
Copy link

antony-k1208 commented Aug 12, 2021

Version

3.2.1

Reproduction link

https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHRlbXBsYXRlPlxuXHQ8aW5wdXQgdHlwZT1cImNoZWNrYm94XCIgaWQ9XCJqYWNrXCIgdmFsdWU9XCJKYWNrXCIgdi1tb2RlbD1cImNoZWNrZWROYW1lc1wiIC8+XG4gIDxsYWJlbCBmb3I9XCJqYWNrXCI+SmFjazwvbGFiZWw+XG4gIDxpbnB1dCB0eXBlPVwiY2hlY2tib3hcIiBpZD1cImpvaG5cIiB2YWx1ZT1cIkpvaG5cIiB2LW1vZGVsPVwiY2hlY2tlZE5hbWVzXCIgLz5cbiAgPGxhYmVsIGZvcj1cImpvaG5cIj5Kb2huPC9sYWJlbD5cbiAgPGlucHV0IHR5cGU9XCJjaGVja2JveFwiIGlkPVwibWlrZVwiIHZhbHVlPVwiTWlrZVwiIHYtbW9kZWw9XCJjaGVja2VkTmFtZXNcIiAvPlxuICA8bGFiZWwgZm9yPVwibWlrZVwiPk1pa2U8L2xhYmVsPlxuICA8YnIgLz5cbiAgPHNwYW4+Q2hlY2tlZCBuYW1lczoge3sgY2hlY2tlZE5hbWVzIH19PC9zcGFuPlxuPC90ZW1wbGF0ZT5cblxuPHNjcmlwdCBzZXR1cD5cbmltcG9ydCB7cmVmfSBmcm9tICd2dWUnO1xuXG5jb25zdCBjaGVja2VkTmFtZXMgPSByZWYoW10pO1xuPC9zY3JpcHQ+In0=

Steps to reproduce

Hey,

when using multiple checkboxes, which are bound to the same array TS2322 arises. See the following image:

image

What is expected?

There shouldn't be a TS error when using an array as v-model.

checkbox's v-model prop is checked(https://v3.vuejs.org/guide/forms.html#basic-usage), and checked type is Booleanish = boolean | 'true' | 'false'(https://github.com/vuejs/vue-next/blob/7ffa225aa334f0fd7da6ba30bee9109de3597643/packages/runtime-dom/types/jsx.d.ts#L458), so number[] can't assign to checked in expected.

What is actually happening?

TS2322 error, since checked needs to be Booleanish.

@LinusBorg
Copy link
Member

It would be great it you could provide an acutal TS example we can run.

@antony-k1208
Copy link
Author

Sorry, I hope this helps: https://codesandbox.io/s/admiring-sky-ucmn0?file=/src/components/HelloWorld.vue

It seems to be only showing this in VS Code with Volar, at least from what I can tell.

@posva
Copy link
Member

posva commented Aug 12, 2021

@johnsoncodehk can you confirm the problem is within vue?

@johnsoncodehk
Copy link
Member

I personal think this is InputHTMLAttributes types problem, hope this comment helpful: johnsoncodehk/vue-tsc#57 (comment)

@yyx990803
Copy link
Member

@johnsoncodehk 77223df should fix the following cases:

  • checkbox with Array v-model value
  • <input> with non-primitive value bindings

However the case for radio needs to be fixed in Volar. Volar is mapping the v-model on a radio input to checked, which is incorrect:

<input type="radio" v-model="selected" :value="foo">
<input type="radio" v-model="selected" :value="bar">

Here v-model's binding type should be the same as :value. Not sure if this can be inferred, but at least it should be any instead of Booleanish.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants
@yyx990803 @posva @LinusBorg @antony-k1208 @johnsoncodehk and others