Repository navigation
Float16Array's definition is incompatible with other typedarraysΒ #62343
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this
Milestone
Description
π Search Terms
Float16Array
π Version & Regression Information
- Tried 5.9.2
- I was unable to test this on prior versions because irrelevant
β― Playground Link
π» Code
export type TypedArrayConstructor =
| Int8ArrayConstructor
| Uint8ArrayConstructor
| Uint8ClampedArrayConstructor
| Int16ArrayConstructor
| Uint16ArrayConstructor
| Int32ArrayConstructor
| Uint32ArrayConstructor
| Float16ArrayConstructor // comment this line out, the error codes away showing that Float16ArrayConstructor is not compatible with other constructors
| Float32ArrayConstructor
| Float64ArrayConstructor;
export type TypedArray =
| Int8Array
| Uint8Array
| Uint8ClampedArray
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Float16Array
| Float32Array
| Float64Array;
export class TypedArrayViewGenerator {
arrayBuffer: ArrayBuffer;
byteOffset: number;
constructor(sizeInBytes: number) {
this.arrayBuffer = new ArrayBuffer(sizeInBytes);
this.byteOffset = 0;
}
getView<T extends TypedArray>(Ctor: TypedArrayConstructor, numElements: number): T {
// gets an error here because `Float16Array` is not following the
// the same pattern as the other typed array views
const view = new Ctor(this.arrayBuffer, this.byteOffset, numElements);
this.byteOffset += view.byteLength;
return view as T;
}
}
export function getView<T extends TypedArray>(arrayBuffer: ArrayBuffer, Ctor: TypedArrayConstructor): T {
// this gets an error too for the same reason
const view = new Ctor(arrayBuffer);
return view as T;
}π Actual behavior
Float16Array should behave the same as other typed array views like Float32Array, Uint32Array etc... It's not
π Expected behavior
Float16Array behaves the same as other typed array views like Float32Array, Uint32Array etc...
Additional information about the issue
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this
Activity
greggman commentedon Aug 27, 2025
I think maybe one or both of these lines
need to be added to
esnext.float16.d.tshere?TypeScript/src/lib/esnext.float16.d.ts
Line 359 in 7956c00
I see similar definitions for other typed arrays. For example
TypeScript/src/lib/es5.d.ts
Line 4366 in 7956c00
Renegade334 commentedon Aug 28, 2025
Looks like the float16 definitions were written prior to #60934 but merged after it, and you're running afoul of the same problem as in the linked issue there. Adding the missing non-generic overloads should indeed solve the problem.