I am trying to conditionally set a spread prop, if isCurrentLocation
is present, but I get the error,
Type ‘RecentSearch | null’ must have a ‘Symbol.iterator’ method that returns an iterator.
Any ideas?
const storeLatestSearch = async (searchToSave: RecentSearch) => {
const newSearches = [
...(searchToSave.isCurrentLocation ? searchToSave : null),
...filteredSearches,
];
Type definition:
export type RecentSearch = {
addressName: string;
id: string;
date: Date;
fuelType: FuelType;
searchDistance: SearchDistance;
isCurrentLocation?: boolean;
searchResults: SearchResult[] | undefined;
};