title: Typescript - Guard against intersection elements
body: <p>How can you make typescript warn on an element level if that array element is present in another array?</p>
  <p>For example:</p>
  <pre><code>const canBeAorB = &lt;A1 extends (&quot;a&quot; | &quot;b&quot;)[]&gt;(arr: A1) =&gt; arr
  
  const arr0 = canBeAorB([&quot;b&quot;, &quot;c&quot;]) // Type '&quot;c&quot;' is not assignable to type '&quot;a&quot; | &quot;b&quot;'.
  </code></pre>
  <p>This is what I want to achieve for TS to warn me on a element that it is invalid</p>
  <p>But instead of a value I need to guard against all elements of other array, for example:</p>
  <pre><code>const blockedElements = [&quot;a&quot;, &quot;b&quot;]
  
  const myArr = [&quot;b&quot;, &quot;c&quot;] // make TS yell that &quot;b&quot; is invalid because its a member of blockedElements 
  </code></pre>
  <p>I managed to get really close by doing this:</p>
  <pre><code>const blockedValues = [&quot;a&quot;, &quot;b&quot;] as const;
  
  type BlockedElement = typeof blockedValues[number];
  
  const cannotHaveBlockedEls = &lt;A1 extends Readonly&lt;Exclude&lt;A1[number], BlockedElement&gt;[]&gt;&gt;(arr: A1) =&gt; arr
  
  const arr3 = cannotHaveBlockedEls([&quot;b&quot;, &quot;c&quot;] as const)
  </code></pre>
  <p>Which will yield:</p>
  <pre><code>Argument of type 'readonly [&quot;b&quot;, &quot;c&quot;]' is not assignable to parameter of type 'readonly &quot;c&quot;[]'.
    Type '&quot;b&quot; | &quot;c&quot;' is not assignable to type '&quot;c&quot;'.
      Type '&quot;b&quot;' is not assignable to type '&quot;c&quot;'
  </code></pre>
  <p>But the error is displayed on top of the whole array argument instead of on top of &quot;b&quot;, my real use case is a larger array where this would really make a difference.</p>
  <p>Is it possible to do?</p>