Select to view content in your preferred language

How do you expose the interfaces used in parameters to other classes

580
4
04-01-2023 12:53 AM
Aeseir
by
Frequent Contributor

I use Typescript for my application and I want to use FeatureLayerProperties to ensure whatever is put through the function, meets the bare minimum requirement for a FeatureLayer for purposes of creation.

 

Currently I am using a parameter:any, because paramenter:FeatureLayerProperties doesn't work, as FeatureLayerProperties is not exported by any arcgis library I have found so far.

 

Is there a way to expose FeatureLayerProperties to custom functions/methods/classes so that we can have strongly typed?

 

0 Kudos
4 Replies
ReneRubalcava
Honored Contributor

You can use some TS utilities to help you out here.

 

type FeatureLayerProp =  InstanceType<typeof FeatureLayer>;

 

https://www.typescriptlang.org/docs/handbook/utility-types.html#instancetypetype

0 Kudos
Aeseir
by
Frequent Contributor

Thanks @ReneRubalcava i actually tried that as fallback option way back but it broke a few times during runtime and stopped that using it.

0 Kudos
Omar_A
by Esri Contributor
Esri Contributor

HI Aeseir,

As far as I know that the FeatureLayerProperties interface is not exported by any ArcGIS library, hence, it cannot be used directly in TypeScript code. However, one workaround way to obtain strong typing is to create a custom interface that extends the FeatureLayerProperties interface and includes any additional properties or restrictions that you require for your specific use case. This custom interface can then be used as the type for your function parameter.

TypeScript: Documentation - Object Types (typescriptlang.org)

Best,

Omar

0 Kudos
Aeseir
by
Frequent Contributor

As you mentioned it is not exported, so you can't build a customer interface that extends unless it is in the file itself where FeatureLayerProperties sits. Which would get overwritten the minute you updated the arcgis sdk, then you back to square one.

Or are you implying another approach that i didn't see in that link?

0 Kudos