title: How can I get the numeric value of an enum variable in TypeScript?
body: <p>I need to upload the numeric value of an enum variable to a REST service.</p>
  
  <p><strong>How can I get the numeric value of the enum variable?</strong></p>
  
  <p>I tried the following two methods:</p>
  
  <pre><code>var enumVar: MyEnum = ...;
  $http.put(url, { enumVar: enumVar });
  </code></pre>
  
  <p>This won't work also:</p>
  
  <pre><code>var enumVar: MyEnum = ...;
  $http.put(url, { enumVar: &lt;number&gt;enumVar });
  </code></pre>
  
  <p>(<code>$http</code> is AngularJS's HTTP service)</p>
  
  <p>Both methods will lead to <code>$http</code> serializing the enum variable as a JSON object:</p>
  
  <pre><code>enumVar: {
      Name: 'MyEnumMemberName',
      Value: 2,
  }
  </code></pre>
  
  <p>instead of just uploading the numeric value:</p>
  
  <pre><code>enumVar: 2,
  </code></pre>
  
  <p><strong>The following works, but it is marked as an error,</strong> since the member <code>.Value</code> does not exist in TypeScript (it exists in Javascript):</p>
  
  <pre><code>var enumVar: MyEnum = ...;
  var enumValue: number = enumVar.Value;
  $http.put(url, enumValue);
  </code></pre>