@types/arcgis-js-api Allow ignoring autocastable properties

446
1
12-02-2020 02:52 AM
EmreCan
New Contributor II

With the current @types/arcgis-js-api it is not possible to autocast classes, because every propertie is required. Furthermore, the property 'type' is missing in the TextSymbolProperties. I can't generate a new TextSymbol like this: 

 

 

layer.featureReduction = {
  type: "cluster",
  labelingInfo: [{
    labelExpressionInfo: {
      expression: "$feature.cluster_count"
    },
    deconflictionStrategy: "none",
    labelPlacement: "center-center",
    symbol: {
      type: "text", // Error 
      color: "white",
      font: {
        size: "12px"
      },
      haloSize: 1,
      haloColor: "black"
    }
  }]
};

 

 

 

I get this error message: 

"Object literal may only specify known properties, and 'type' does not exist in type 'TextSymbolProperties | LabelSymbol3DProperties'"

 

I have to use // @ts-ignore over and over.

And this is just an example. The same could be applied to many things!

0 Kudos
1 Reply
ReneRubalcava
Frequent Contributor II

This is a limitation of TypeScript because we can't have different types for getters and setters. So you can't get clean autocasting in this manner. You could type the props "as any", but still not ideal. For TypeScript it is recommended you new up instances as needed.

0 Kudos