title: Does TypeScript have an equivalent of ES6 "Sets"
body: <p>I want to extract all the unique properties from an array of objects, you can do so in ES6 very cleanly using the spread operator and the <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Set" rel="noreferrer">Set</a> so: </p>
  
  <pre><code>var arr = [ {foo:1, bar:2}, {foo:2, bar:3}, {foo:3, bar:3} ]   
  const uniqueBars = [... new Set(arr.map(obj =&gt; obj.bar))];
  
  &gt;&gt; [2, 3]
  </code></pre>
  
  <p>However, in TypeScript 1.8.31 this gives me the build error:</p>
  
  <blockquote>
    <p>Cannot find name 'Set'</p>
  </blockquote>
  
  <p>I know I can force VS to ignore it by using </p>
  
  <pre><code>declare var Set;
  </code></pre>
  
  <p>But I'm hoping for something TypeScript will compile into non-ES6 so that it could be used on older systems.</p>
  
  <p>Does anyone know if there's such a feature I could use? </p>
  
  <p><strong>Edit</strong>:</p>
  
  <p>Actually, even when I use <code>declare var Set;</code>, the above code compiles but throws this error repeatedly, so I'm not sure how to use it even without compiling down:</p>
  
  <blockquote>
    <p>Uncaught TypeError: (intermediate value).slice is not a function</p>
  </blockquote>
  
  <p>How can I update my code to use <code>Set</code> in TypeScript?</p>