I try to follow the doc to add a layer as custom source for the Search widget: https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search.html#sources
But I get:
The full error is -
Type '{ layer: FeatureLayer; }' is not assignable to type 'SearchSourceProperties'.Object literal may only specify known properties, and 'layer' does not exist in type 'SearchSourceProperties'.ts(2322)
How should I add a FeatureLayer as source to the Search widget? I am using 4.25.5 ES module version.
This sample shows how to use the layer as a search source. There are other options you need to set, like what fields to search and stuff.
https://developers.arcgis.com/javascript/latest/sample-code/widgets-search-multiplesource/
That is a TypeScript typing issue. TypeScript doesn't type autocasted properties, so you need to instantiate it as an instance of the SearchSource.
https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Search-SearchSource.html
sources: [new SearchSource({ layer, ...otherstuff })]
Might need to instantiate some other stuff to make TypeScript happy.
Thanks. But would you show me some code for a working JavaScript version? The code compiled regardlessly but the search did not show me any result from the layer.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.