Question:
I have the following two typesversion
in value
objectdesc
is printed out but I get this error in vs code. I could avoid this error by casting the SortOption
object to anyAnswer:
You’ve definedSortOption
as this type:item.value
might be a string
or it might be a Record<string, 'desc' | 'asc'>
.For instance, this is also a valid
Item
:Record
you have to prove it is one first at runtime in order to narrow down the type.For example:
If you have better answer, please add a comment about this, thank you!