<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: typescript in Graphic constructor in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/typescript-in-graphic-constructor/m-p/1209544#M78582</link>
    <description>&lt;P&gt;Autocasting doesn't cooperate so well with TypeScript. Per:&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/programming-patterns/#autocasting" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/programming-patterns/#autocasting&lt;/A&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Currently, due to limitations in TypeScript, autocasting works best in non-TypeScript applications.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;If you cast your object literals to "any", you'll dodge TypeScript checking and it will compile without errors. You just have to be more certain about the properties you're setting though, because there'll be nothing protecting you from typos, providing unexpected types, etc. Basically, you have to forego the type-checking of TypeScript.&lt;/P&gt;&lt;P&gt;Like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const hexGraphic = new Graphic({
      geometry: {
        type: 'polygon',
        rings: [[
          [-116.83830158928454, 32.26038282119406],
          [-115.25400548040932, 33.43153649157358],
          [-115.64454936135779, 35.138559675017866],
          [-117.66644115562842, 35.657119683574905],
          [-119.2405536967384, 34.468622114983724],
          [-118.8045281400983, 32.77943799663874],
          [-116.83830158928454, 32.26038282119406]
        ]]
      } as any,
      attributes: {
        h3: '8229a7fffffffff',
        count: 17324
      } as any,
      symbol: simpleFillSymbol,
      popupTemplate: graphicPopupTemplate
    })&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 03 Sep 2022 23:35:05 GMT</pubDate>
    <dc:creator>JasonDoingMaps</dc:creator>
    <dc:date>2022-09-03T23:35:05Z</dc:date>
    <item>
      <title>typescript in Graphic constructor</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/typescript-in-graphic-constructor/m-p/1209531#M78580</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I'm constructing a Graphic and the geometry type is not recognized by TypeScript, saying&lt;/P&gt;&lt;LI-CODE lang="c"&gt;Type '{ type: string; rings: number[][][]; }' is not assignable to type 'GeometryProperties'.
  Object literal may only specify known properties, and 'type' does not exist in type 'GeometryProperties'.ts(2322)
arcgis-js-api.d.ts(7670, 5): The expected type comes from property 'geometry' which is declared here on type 'GraphicProperties'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It looks to me as if the Geometry type definition should allow this. Sample code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const hexGraphic = new Graphic({
      geometry: {
        type: 'polygon',
        rings: [[
          [-116.83830158928454, 32.26038282119406],
          [-115.25400548040932, 33.43153649157358],
          [-115.64454936135779, 35.138559675017866],
          [-117.66644115562842, 35.657119683574905],
          [-119.2405536967384, 34.468622114983724],
          [-118.8045281400983, 32.77943799663874],
          [-116.83830158928454, 32.26038282119406]
        ]]
      },
      attributes: {
        h3: '8229a7fffffffff',
        count: 17324
      },
      symbol: simpleFillSymbol,
      popupTemplate: graphicPopupTemplate
    })&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 03 Sep 2022 20:28:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/typescript-in-graphic-constructor/m-p/1209531#M78580</guid>
      <dc:creator>john_cartwright_noaa</dc:creator>
      <dc:date>2022-09-03T20:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: typescript in Graphic constructor</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/typescript-in-graphic-constructor/m-p/1209544#M78582</link>
      <description>&lt;P&gt;Autocasting doesn't cooperate so well with TypeScript. Per:&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/programming-patterns/#autocasting" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/programming-patterns/#autocasting&lt;/A&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Currently, due to limitations in TypeScript, autocasting works best in non-TypeScript applications.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;If you cast your object literals to "any", you'll dodge TypeScript checking and it will compile without errors. You just have to be more certain about the properties you're setting though, because there'll be nothing protecting you from typos, providing unexpected types, etc. Basically, you have to forego the type-checking of TypeScript.&lt;/P&gt;&lt;P&gt;Like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const hexGraphic = new Graphic({
      geometry: {
        type: 'polygon',
        rings: [[
          [-116.83830158928454, 32.26038282119406],
          [-115.25400548040932, 33.43153649157358],
          [-115.64454936135779, 35.138559675017866],
          [-117.66644115562842, 35.657119683574905],
          [-119.2405536967384, 34.468622114983724],
          [-118.8045281400983, 32.77943799663874],
          [-116.83830158928454, 32.26038282119406]
        ]]
      } as any,
      attributes: {
        h3: '8229a7fffffffff',
        count: 17324
      } as any,
      symbol: simpleFillSymbol,
      popupTemplate: graphicPopupTemplate
    })&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Sep 2022 23:35:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/typescript-in-graphic-constructor/m-p/1209544#M78582</guid>
      <dc:creator>JasonDoingMaps</dc:creator>
      <dc:date>2022-09-03T23:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: typescript in Graphic constructor</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/typescript-in-graphic-constructor/m-p/1210176#M78606</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/532492"&gt;@john_cartwright_noaa&lt;/a&gt; like &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/536567"&gt;@JasonDoingMaps&lt;/a&gt; mentioned, TypeScript limitations cause autocasting to throw errors during the build process. Are you using ESM or AMD modules?&lt;/P&gt;&lt;P&gt;The best practice when you run into TypeScript autocasting errors is to break out individual Classes and properties along with their actual types, this way you can maintain type safety. All API modules are typed, for non-module typings you might need to use the __esri namespace.&lt;/P&gt;&lt;P&gt;Here is an "@arcgis/core" ESM example. For those reading this that aren't aware, the ES modules include the typings with the npm install. In this example the typings are inferred, and I've shortened the sample for brevity:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import Graphic from "@arcgis/core/Graphic";
import Polygon from "@arcgis/core/geometry/Polygon";

    const hexGraphic = new Graphic({
      // Use an instance of Polygon here
      geometry: new Polygon({
        rings: [[
          [-116.83830158928454, 32.26038282119406],
          [-115.25400548040932, 33.43153649157358],
          [-115.64454936135779, 35.138559675017866],
          [-117.66644115562842, 35.657119683574905],
          [-119.2405536967384, 34.468622114983724],
          [-118.8045281400983, 32.77943799663874],
          [-116.83830158928454, 32.26038282119406]
        ]]
      }),
      attributes: {
        h3: '8229a7fffffffff',
        count: 17324
      }
    })&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 00:24:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/typescript-in-graphic-constructor/m-p/1210176#M78606</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2022-09-07T00:24:23Z</dc:date>
    </item>
  </channel>
</rss>

