From fe79fa3218261616c3c5aca4c9717a8cd3471192 Mon Sep 17 00:00:00 2001 From: Renegade334 Date: Tue, 10 Mar 2026 01:31:55 +0000 Subject: [PATCH] typings: rationalise TypedArray types --- typings/globals.d.ts | 14 +++++++++ typings/primordials.d.ts | 61 ++++++++++++---------------------------- 2 files changed, 32 insertions(+), 43 deletions(-) diff --git a/typings/globals.d.ts b/typings/globals.d.ts index 739f3d9a534026..ddd5885faa057f 100644 --- a/typings/globals.d.ts +++ b/typings/globals.d.ts @@ -87,6 +87,20 @@ declare global { | BigUint64Array | BigInt64Array; + type TypedArrayConstructor = + | typeof Uint8Array + | typeof Uint8ClampedArray + | typeof Uint16Array + | typeof Uint32Array + | typeof Int8Array + | typeof Int16Array + | typeof Int32Array + | typeof Float16Array + | typeof Float32Array + | typeof Float64Array + | typeof BigUint64Array + | typeof BigInt64Array; + namespace NodeJS { interface Global { internalBinding(binding: T): InternalBindingMap[T] diff --git a/typings/primordials.d.ts b/typings/primordials.d.ts index 204c12b0087f91..5437ac2736792a 100644 --- a/typings/primordials.d.ts +++ b/typings/primordials.d.ts @@ -19,7 +19,7 @@ type UncurryGetter = type UncurrySetter = O[K] extends infer V ? (self: T, value: V) => void : never; -type TypedArrayContentType = T extends { [k: number]: infer V } ? V : never; +type TypedArrayContentType = InstanceType[number]; /** * Primordials are a way to safely use globals without fear of global mutation @@ -472,14 +472,12 @@ declare namespace primordials { export const SyntaxErrorPrototype: typeof SyntaxError.prototype export import TypeError = globalThis.TypeError; export const TypeErrorPrototype: typeof TypeError.prototype - export function TypedArrayFrom( - constructor: new (length: number) => T, - source: - | Iterable> - | ArrayLike>, - ): T; - export function TypedArrayFrom( - constructor: new (length: number) => T, + export function TypedArrayFrom( + constructor: T, + source: Iterable> | ArrayLike>, + ): InstanceType + export function TypedArrayFrom( + constructor: T, source: Iterable | ArrayLike, mapfn: ( this: THIS_ARG, @@ -487,28 +485,17 @@ declare namespace primordials { index: number, ) => TypedArrayContentType, thisArg?: THIS_ARG, - ): T; - export function TypedArrayOf( - constructor: new (length: number) => T, - ...items: readonly TypedArrayContentType[] - ): T; - export function TypedArrayOfApply( - constructor: new (length: number) => T, + ): InstanceType; + export function TypedArrayOf( + constructor: T, + ...items: TypedArrayContentType[], + ): InstanceType; + export function TypedArrayOfApply( + constructor: T, items: readonly TypedArrayContentType[], - ): T; - export const TypedArray: TypedArray; - export const TypedArrayPrototype: - | typeof Uint8Array.prototype - | typeof Int8Array.prototype - | typeof Uint16Array.prototype - | typeof Int16Array.prototype - | typeof Uint32Array.prototype - | typeof Int32Array.prototype - | typeof Float32Array.prototype - | typeof Float64Array.prototype - | typeof BigInt64Array.prototype - | typeof BigUint64Array.prototype - | typeof Uint8ClampedArray.prototype; + ): InstanceType; + export const TypedArray: TypedArrayConstructor; + export const TypedArrayPrototype: TypedArrayConstructor["prototype"]; export const TypedArrayPrototypeGetBuffer: UncurryGetter; export const TypedArrayPrototypeGetByteLength: UncurryGetter; export const TypedArrayPrototypeGetByteOffset: UncurryGetter; @@ -519,19 +506,7 @@ declare namespace primordials { export function TypedArrayPrototypeSet(self: T, ...args: Parameters): ReturnType; export function TypedArrayPrototypeSubarray(self: T, ...args: Parameters): ReturnType; export function TypedArrayPrototypeSlice(self: T, ...args: Parameters): ReturnType; - export function TypedArrayPrototypeGetSymbolToStringTag(self: unknown): - | 'Int8Array' - | 'Int16Array' - | 'Int32Array' - | 'Uint8Array' - | 'Uint16Array' - | 'Uint32Array' - | 'Uint8ClampedArray' - | 'BigInt64Array' - | 'BigUint64Array' - | 'Float32Array' - | 'Float64Array' - | undefined; + export function TypedArrayPrototypeGetSymbolToStringTag(self: unknown): TypedArray[typeof Symbol.toStringTag] | undefined; export import URIError = globalThis.URIError; export const URIErrorPrototype: typeof URIError.prototype export import Uint16Array = globalThis.Uint16Array;