<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// https://msdn.microsoft.com/en-us/library/windows/apps/hh700334.aspx

tempFolder.createFileAsync(&quot;tempfile.txt&quot;, Windows.Storage.CreationCollisionOption.replaceExisting)
   .then(function (tempFile) {
       // The createFileAsync call succeeded, so start the download operation.
       var downloader = new Windows.Networking.BackgroundTransfer.BackgroundDownloader();
       var transfer = downloader.createDownload(uriExample, tempFile);
        return transfer.startAsync(); 
   })"><pre class="notranslate"><span class="pl-c">// https://msdn.microsoft.com/en-us/library/windows/apps/hh700334.aspx</span>

<span class="pl-s1">tempFolder</span><span class="pl-kos">.</span><span class="pl-en">createFileAsync</span><span class="pl-kos">(</span><span class="pl-s">"tempfile.txt"</span><span class="pl-kos">,</span> <span class="pl-v">Windows</span><span class="pl-kos">.</span><span class="pl-c1">Storage</span><span class="pl-kos">.</span><span class="pl-c1">CreationCollisionOption</span><span class="pl-kos">.</span><span class="pl-c1">replaceExisting</span><span class="pl-kos">)</span>
   <span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">tempFile</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
       <span class="pl-c">// The createFileAsync call succeeded, so start the download operation.</span>
       <span class="pl-k">var</span> <span class="pl-s1">downloader</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">Windows</span><span class="pl-kos">.</span><span class="pl-c1">Networking</span><span class="pl-kos">.</span><span class="pl-c1">BackgroundTransfer</span><span class="pl-kos">.</span><span class="pl-c1">BackgroundDownloader</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
       <span class="pl-k">var</span> <span class="pl-s1">transfer</span> <span class="pl-c1">=</span> <span class="pl-s1">downloader</span><span class="pl-kos">.</span><span class="pl-en">createDownload</span><span class="pl-kos">(</span><span class="pl-s1">uriExample</span><span class="pl-kos">,</span> <span class="pl-s1">tempFile</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-k">return</span> <span class="pl-s1">transfer</span><span class="pl-kos">.</span><span class="pl-en">startAsync</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span> 
   <span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">Copy-pasting this to Visual Studio makes this (with 2-space indent):</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="tempFolder.createFileAsync(&quot;tempfile.txt&quot;, Windows.Storage.CreationCollisionOption.replaceExisting)
  .then(function (tempFile) {
  // The createFileAsync call succeeded, so start the download operation.
  var downloader = new Windows.Networking.BackgroundTransfer.BackgroundDownloader();
  var transfer = downloader.createDownload(uriExample, tempFile);
  return transfer.startAsync();
})"><pre class="notranslate"><span class="pl-s1">tempFolder</span><span class="pl-kos">.</span><span class="pl-en">createFileAsync</span><span class="pl-kos">(</span><span class="pl-s">"tempfile.txt"</span><span class="pl-kos">,</span> <span class="pl-smi">Windows</span><span class="pl-kos">.</span><span class="pl-c1">Storage</span><span class="pl-kos">.</span><span class="pl-c1">CreationCollisionOption</span><span class="pl-kos">.</span><span class="pl-c1">replaceExisting</span><span class="pl-kos">)</span>
  <span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">tempFile</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-c">// The createFileAsync call succeeded, so start the download operation.</span>
  <span class="pl-k">var</span> <span class="pl-s1">downloader</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">Windows</span><span class="pl-kos">.</span><span class="pl-c1">Networking</span><span class="pl-kos">.</span><span class="pl-c1">BackgroundTransfer</span><span class="pl-kos">.</span><span class="pl-c1">BackgroundDownloader</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-k">var</span> <span class="pl-s1">transfer</span> <span class="pl-c1">=</span> <span class="pl-s1">downloader</span><span class="pl-kos">.</span><span class="pl-en">createDownload</span><span class="pl-kos">(</span><span class="pl-s1">uriExample</span><span class="pl-kos">,</span> <span class="pl-s1">tempFile</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-k">return</span> <span class="pl-s1">transfer</span><span class="pl-kos">.</span><span class="pl-en">startAsync</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">This in fact worked in older version of TypeScript (I think the last version was 1.1), but now it's hard to make Promise chains.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// This is how I deal with Promise now
somePromise().then(() =&gt; {
}).then(() =&gt; {
});

// Not good...
somePromise().then(() =&gt; otherPromise(
  param1,
  &quot;long-string, let's say it's a URL.&quot;
  ).then(() =&gt; {
  blah();
});

// Doesn't work
somePromise()
  .then(() =&gt; otherPromise(
  param1,
  &quot;long-string, let's say it's a URL.&quot;
  )
  .then(() =&gt; {
  blah();
});"><pre class="notranslate"><span class="pl-c">// This is how I deal with Promise now</span>
<span class="pl-en">somePromise</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-c">// Not good...</span>
<span class="pl-en">somePromise</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">then</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-en">otherPromise</span><span class="pl-kos">(</span>
  <span class="pl-s1">param1</span><span class="pl-kos">,</span>
  <span class="pl-s">"long-string, let's say it's a URL."</span>
  <span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-en">blah</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-c">// Doesn't work</span>
<span class="pl-s1">somePromise</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
  <span class="pl-kos">.</span><span class="pl-c1">then</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-en">otherPromise</span><span class="pl-kos">(</span>
  <span class="pl-s1">param1</span><span class="pl-kos">,</span>
  <span class="pl-s">"long-string, let's say it's a URL."</span>
  <span class="pl-kos">)</span>
  <span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
  <span class="pl-en">blah</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Can we get this better so that the MSDN example just work?</p>
<p dir="auto">I have the following code:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    query(id: number) {
        return this.$http
            .get('/api/Entity/' + id)
            .then(function (data) {
            return data.data;     // (a)
        });                       // (b)
    }"><pre class="notranslate">    <span class="pl-en">query</span><span class="pl-kos">(</span><span class="pl-s1">id</span>: <span class="pl-s1">number</span><span class="pl-kos">)</span><span class="pl-kos"></span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">$http</span>
            <span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s">'/api/Entity/'</span> <span class="pl-c1">+</span> <span class="pl-s1">id</span><span class="pl-kos">)</span>
            <span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">data</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-k">return</span> <span class="pl-s1">data</span><span class="pl-kos">.</span><span class="pl-c1">data</span><span class="pl-kos">;</span>     <span class="pl-c">// (a)</span>
        <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>                       <span class="pl-c">// (b)</span>
    <span class="pl-kos">}</span></pre></div>
<p dir="auto">When  I type the semi-colon at point (a), it gets correctly indented. When a type a semi-colon at point (b), both lines get 4 columns to the left, which is the same output when a format the whole document.</p>
<p dir="auto">I must add it gets on my nerves.</p>
<p dir="auto">Any way to avoid it? Tks</p>