When I perform a search for e.g. “Straße des 17. Juni Berlin
” in the SearchBox, I receive results that include an object with properties such as type
, id
, and address
. I can confirm that I can successfully access properties like result.type
in my code using console.log(result.type)
:
My Code:
const searchBox = new SearchBox(tt.services, {
idleTimePress: 1000,
minNumberOfCharacters: 2,
searchOptions: {
key: TT_API_KEY,
language: 'de-DE',
countrySet: 'DE'
},
labels: {
placeholder: 'Addresse',
noResultsMessage: 'Kein Ergebnis.'
},
filterSearchResults: (result: void): boolean => {
console.log(result.type);
switch (result.type) {
case 'POI':
return false;
case 'Address':
return true;
default:
return true;
}
}
})
Why do I filter the results? I want to get only some specific types i.e. addresses and no POI, brands or other.
Result In Console:
{
"type": "Street",
"id": "cYCcdwhKpYDg9ATB3Qx3sQ",
"score": 10.8427696228,
"address": {
"streetName": "Straße des 17. Juni",
"municipalitySubdivision": "Charlottenburg",
"municipality": "Berlin",
"countrySecondarySubdivision": "Berlin",
"countrySubdivision": "Berlin",
"postalCode": "10587, 10623",
"countryCode": "DE",
"country": "Deutschland",
"countryCodeISO3": "DEU",
"freeformAddress": "Straße des 17. Juni, 10587, 10623 Berlin",
"localName": "Berlin"
},
"position": {
"lng": 13.329641,
"lat": 52.513473
},
"viewport": {
"topLeftPoint": {
"lng": 13.3228,
"lat": 52.51443
},
"btmRightPoint": {
"lng": 13.33625,
"lat": 52.51248
}
},
"__resultListIdx__": 0
}
However, the provided type signature filterSearchResults?: () => void;
in the documentation does not seem to match this usage pattern. How I filter something I have already learned here: How does tt.plugins.SearchBox.filterSearchResults work? applied accordingly. Now (logically) TypeScript marks the result.type as an error, because according to the package type definition result is defined as void. In my opinion there is an error in the documentation, because clearly result is not void.