#Property  value  does not exist on type  never

14 messages · Page 1 of 1 (latest)

summer trout
#

I am very new to typescript and can't figure out why I am getting this error: Property  value  does not exist on type  never.
Here is the code where it is being thrown:

if (e.target.checked) {
    // it is checked, add the filter to columnFilters
    setColumnFilters((prevState: []) => {
        const categories = prevState.find(
            (filter: { id: string; value: string[] }) =>
                filter.id === filterCol
        )?.value;
#

That last 'value' word is being underlined in my IDE with the above error.

compact torrent
#

you're typing prevState to be an empty tuple, which just doesn't have elements

#

you're likely typing that incorrectly?

summer trout
#

like I said, I'm pretty new 🙂 It is an array type, so I was declaring it as type array.

#

but it could be empty or have those filter objects in it

keen iron
#

[] means an array that can never have anything, you need to give it a type to tell TS what could be in the array.

#

string[] if you want an array that has strings, for example.

summer trout
#

aw i see

#

so, something like { id: string; value: string[] }[]

compact torrent
#

sure

summer trout
#

beautiful! Thank you!

#

How do I mark this resolved?

compact torrent
#

!resolved or !close