<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="const array: Uint8Array = new Float32Array(0);"><pre class="notranslate"><code class="notranslate">const array: Uint8Array = new Float32Array(0);
</code></pre></div>
<p dir="auto">This is difference types, but typescript not see errors =\</p>
<p dir="auto">All typed arrays are assignable in our present dts.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="let arr = new Uint8Array(20);
let arr2 = new Int16Array(20);
arr = arr2; // Valid."><pre class="notranslate"><span class="pl-k">let</span> <span class="pl-s1">arr</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">Uint8Array</span><span class="pl-kos">(</span><span class="pl-c1">20</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">let</span> <span class="pl-s1">arr2</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">Int16Array</span><span class="pl-kos">(</span><span class="pl-c1">20</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">arr</span> <span class="pl-c1">=</span> <span class="pl-s1">arr2</span><span class="pl-kos">;</span> <span class="pl-c">// Valid.</span></pre></div>
<p dir="auto">The same is true of specific errors:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="let err = new SyntaxError();
let err2 = new RangeError();
err = err2; // Also valid"><pre class="notranslate"><span class="pl-k">let</span> <span class="pl-s1">err</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">SyntaxError</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">let</span> <span class="pl-s1">err2</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">RangeError</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">err</span> <span class="pl-c1">=</span> <span class="pl-s1">err2</span><span class="pl-kos">;</span> <span class="pl-c">// Also valid</span></pre></div>
<p dir="auto">We should fix this, as both of these sets of types are sets whose members are meant to be distinguished by type rather than by structure. This is really important in the case of typed arrays, as the following happens:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="let arr = new Uint8Array(20);
let arr2 = new Int16Array(20);
arr = arr2; // Valid.
let sliced = arr.slice(0, 10); // Typed as a Uint8Array (really an Int16Array at runtime)"><pre class="notranslate"><span class="pl-k">let</span> <span class="pl-s1">arr</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">Uint8Array</span><span class="pl-kos">(</span><span class="pl-c1">20</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">let</span> <span class="pl-s1">arr2</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">Int16Array</span><span class="pl-kos">(</span><span class="pl-c1">20</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">arr</span> <span class="pl-c1">=</span> <span class="pl-s1">arr2</span><span class="pl-kos">;</span> <span class="pl-c">// Valid.</span>
<span class="pl-k">let</span> <span class="pl-s1">sliced</span> <span class="pl-c1">=</span> <span class="pl-s1">arr</span><span class="pl-kos">.</span><span class="pl-en">slice</span><span class="pl-kos">(</span><span class="pl-c1">0</span><span class="pl-kos">,</span> <span class="pl-c1">10</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// Typed as a Uint8Array (really an Int16Array at runtime)</span></pre></div>