<?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: How to await MapView with TypeScript in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-await-mapview-with-typescript/m-p/236171#M22002</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I haven't started using await yet but if I get a chance I'll try this out&amp;nbsp;and see if I can replicate this issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Promises returned by the JS API tend to be a little different from the standard JS promises and this could possibly be related to this&amp;nbsp;issue (the type is IPromise, based on dojo/deferred):&amp;nbsp;&lt;A class="link-titled" href="https://github.com/Esri/jsapi-resources/blob/master/4.x/typescript/arcgis-js-api.d.ts#L10" title="https://github.com/Esri/jsapi-resources/blob/master/4.x/typescript/arcgis-js-api.d.ts#L10"&gt;jsapi-resources/arcgis-js-api.d.ts at master · Esri/jsapi-resources · GitHub&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 20 Jun 2017 23:28:32 GMT</pubDate>
    <dc:creator>ThomasSolow</dc:creator>
    <dc:date>2017-06-20T23:28:32Z</dc:date>
    <item>
      <title>How to await MapView with TypeScript</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-await-mapview-with-typescript/m-p/236170#M22001</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm using TypeScript and wondering&amp;nbsp;if there's a better way to&amp;nbsp;await a &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html" rel="nofollow noopener noreferrer" target="_blank"&gt;MapView&lt;/A&gt; than what I'm currently doing.&amp;nbsp;The example in the documentation shows how to supply a callback for&amp;nbsp;the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#then" rel="nofollow noopener noreferrer" target="_blank"&gt;then &lt;/A&gt;promise when using vanilla JavaScript:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; view &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;new&lt;/SPAN&gt; &lt;SPAN class="token class-name"&gt;MapView&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
view&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;then&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;function&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp; &lt;SPAN class="comment token"&gt;// This code will execute once the promise is resolved&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I'd like to do is use the await keyword to avoid the nested function call.&amp;nbsp;This is the only way I've been able get this to work:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;let&lt;/SPAN&gt; view &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;new&lt;/SPAN&gt; &lt;SPAN class="token class-name"&gt;MapView&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;await&lt;/SPAN&gt; view&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;then&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;// This code will execute once the promise is resolved&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Ideally I would be able to write something like this:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;let&lt;/SPAN&gt; view &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;new&lt;/SPAN&gt; &lt;SPAN class="token class-name"&gt;MapView&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;await&lt;/SPAN&gt; view&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;// this code will execute after the promise is resolved&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Although it doesn't compile with this error:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Alan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:54:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-await-mapview-with-typescript/m-p/236170#M22001</guid>
      <dc:creator>AlanMervitz</dc:creator>
      <dc:date>2021-12-11T11:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to await MapView with TypeScript</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-await-mapview-with-typescript/m-p/236171#M22002</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I haven't started using await yet but if I get a chance I'll try this out&amp;nbsp;and see if I can replicate this issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Promises returned by the JS API tend to be a little different from the standard JS promises and this could possibly be related to this&amp;nbsp;issue (the type is IPromise, based on dojo/deferred):&amp;nbsp;&lt;A class="link-titled" href="https://github.com/Esri/jsapi-resources/blob/master/4.x/typescript/arcgis-js-api.d.ts#L10" title="https://github.com/Esri/jsapi-resources/blob/master/4.x/typescript/arcgis-js-api.d.ts#L10"&gt;jsapi-resources/arcgis-js-api.d.ts at master · Esri/jsapi-resources · GitHub&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jun 2017 23:28:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-await-mapview-with-typescript/m-p/236171#M22002</guid>
      <dc:creator>ThomasSolow</dc:creator>
      <dc:date>2017-06-20T23:28:32Z</dc:date>
    </item>
  </channel>
</rss>

