Open
Description
🔎 Search Terms
When creating a class for a typed array, if this class is returned by indexing into an object, I get a compile error.
See attached playground link.
🕗 Version & Regression Information
- This changed between versions 5.7.3 and 5.4.2, it used to work in 5.4.2
⏯ Playground Link
💻 Code
export type TypedArrayConstructor =
| Uint8ArrayConstructor
| Uint16ArrayConstructor
| Uint32ArrayConstructor
| Int8ArrayConstructor
| Int16ArrayConstructor
| Int32ArrayConstructor
| Float32ArrayConstructor
export const Constants = {
BYTE: 5120,
UNSIGNED_BYTE: 5121,
SHORT: 5122,
UNSIGNED_SHORT: 5123,
INT: 5124,
UNSIGNED_INT: 5125,
FLOAT: 5126,
}
export const arrayByType = {
[Constants.BYTE] : Int8Array,
[Constants.UNSIGNED_BYTE] : Uint8Array,
[Constants.SHORT] : Int16Array,
[Constants.UNSIGNED_SHORT] : Uint16Array,
[Constants.INT] : Int32Array,
[Constants.UNSIGNED_INT] : Uint32Array,
[Constants.FLOAT] : Float32Array,
} as const;
const buffer = new ArrayBuffer();
// Ok
{
const ArrayClass: TypedArrayConstructor = Int8Array;
const c = new ArrayClass(buffer, 0, 1);
}
// Compile Error
{
const componentType = Constants.BYTE;
const ArrayClass: TypedArrayConstructor = arrayByType[componentType];
const c = new ArrayClass(buffer, 0, 1); // Expected 0-1 arguments
}
🙁 Actual behavior
The last line returns a compile error.
🙂 Expected behavior
There should be no compile errors.
Additional information about the issue
No response