-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
Bug Report
🔎 Search Terms
TypedArray, assignable, wellknown, Symbol
🕗 Version & Regression Information
AFAIK, this as been a problem ever since type .d.ts
files were created for the TypedArray
types.
The only way TS seems to distinguish between the various TypedArray
types is by using the Symbol.toStringTag
singleton string type defined in lib.es2015.symbol.wellknown.d.ts
When compiling for an ES5 environment, we would prefer not to include that .d.ts
file.
Including it increases the risk that a developer will try to use some well-known Symbol
value that cannot be polyfiled.
This could result in a runtime error later because the symbol doesn't exist.
Leaving it out makes TS think you can assign e.g. a UintArray
to a Float32Array
.
⏯ Playground Link
This example shows that it is possible to just assign a Uint8Array
to a Float32Array
when TS is configured for ES5.
💻 Code
function expectUint8Array(uint8Array: Uint8Array): Float32Array {
return uint8Array; // no error here
}
🙁 Actual behavior
TS allowed assignment from Uint8Array
to Float32Array
with no error reported.
🙂 Expected behavior
TS should have reported an error.