Cannot add a FeatureLayer to the Search widget as a source

673
3
Jump to solution
01-31-2023 01:14 PM
noah
by
New Contributor II

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:

Screenshot 2023-01-31 at 16.04.01.png

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.

0 Kudos
2 Solutions

Accepted Solutions
ReneRubalcava
Frequent Contributor

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. 

View solution in original post

0 Kudos
ReneRubalcava
Frequent Contributor

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/

View solution in original post

0 Kudos
3 Replies
ReneRubalcava
Frequent Contributor

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. 

0 Kudos
noah
by
New Contributor II

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.

0 Kudos
ReneRubalcava
Frequent Contributor

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/

0 Kudos