sagalbot / vue-select

Everything you wish the HTML <select> element could do, wrapped up into a lightweight, extensible Vue component.
https://vue-select.org
MIT License
4.62k stars 1.33k forks source link

reduce prop has implicit any as type #1671

Closed colinblaise closed 2 years ago

colinblaise commented 2 years ago

Please respect maintainers time by filling in these sections. Your issue will likely be closed without this information.

Describe the bug A clear and concise description of what the bug is.

image

Reproduction Link A link to a reproduction of the bug. This is a huge help.

Steps To Reproduce Outline the steps to reproduce the bug.

Use vue-select with vue 2.7.6 and VS Code Volar extension

Expected behavior A clear and concise description of what you expected to happen.

Ideally it infers the type (maybe based on the options prop

Screenshots If applicable, add screenshots to help explain your problem.

colinblaise commented 2 years ago

There's a very simple work around.

Just don't use anonymous functions in template. Instead define a method and pass that to the reduce prop.

Closing since my issue is resolved

sagalbot commented 2 years ago

This is a typescript error in your application code, not vue select. You can solve this by adding the type in your function declaration:

<v-select :reduce="(tag: { id: number }) => tag.id" />
hiro-lapis commented 1 month ago

I encountered the same issue and I'd add that it it true the solution is adding the type in a function declaration.

But we need to pass named type, not object literal.

:reduce="(tag: { id: number }) => tag.id" // remain TS error

:reduce="(tag: TagOption) => tag.id" // work!