My eyes have been fixed on this code for quite some time now...
I need assistance
I am currently working with a filter and trying to eliminate undefined objects from an array:
.then((items) => {
const filtered = items.map( i => {
if (i !== undefined) {
return i
}
})
updateState(filtered, query)
});
However, I encountered an error while using the filtered data:
Argument of type '({ service: Service; results: Card[]; } | undefined)[]' is not assignable to parameter of type 'SearchResult[]'.
Type '{ service: Service; results: Card[]; } | undefined' is not assignable to type 'SearchResult'.
Type 'undefined' is not assignable to type 'SearchResult'.
Why am I facing this issue when trying to pass it to the updateState() function?
Isn't the purpose of the filter to remove undefined items from the array.. What could be causing this problem?
EDIT: Even after filtering with type assertion, the same error persists..
const filtered: SearchResult[] = results.filter( i => i as SearchResult)
Getting the same outcome...
Thank you