Skip to content

Combobox itemToString prop treats item object as string #793

Answered by SiTaggart
yannieyip asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @yannieyip

I suspect this is Typescript errors not being particular helpful, but it is doing what it should be doing in terms of type checking.

Item is typed to be either a string or an object. Currently your code only proves to Typescript that item exists. At the point at which you try to get name from item, Typescript still thinks it could either be a string or an object, so it's complaining. The first part of the error is misleading. I suspect if you check that item is not a string before you pull name off of it, you'll clear the error.

Let us know how you get on.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by serifluous
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants