Skip to content

Commit 6c8fa42

Browse files
Renegade334aduh95
authored andcommitted
typings: rationalise TypedArray types
PR-URL: #62174 Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
1 parent 0000d2f commit 6c8fa42

2 files changed

Lines changed: 32 additions & 43 deletions

File tree

‎typings/globals.d.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ declare global {
8787
|BigUint64Array
8888
|BigInt64Array;
8989

90+
typeTypedArrayConstructor=
91+
|typeofUint8Array
92+
|typeofUint8ClampedArray
93+
|typeofUint16Array
94+
|typeofUint32Array
95+
|typeofInt8Array
96+
|typeofInt16Array
97+
|typeofInt32Array
98+
|typeofFloat16Array
99+
|typeofFloat32Array
100+
|typeofFloat64Array
101+
|typeofBigUint64Array
102+
|typeofBigInt64Array;
103+
90104
namespaceNodeJS{
91105
interfaceGlobal{
92106
internalBinding<TextendsInternalBindingKeys>(binding: T): InternalBindingMap[T]

‎typings/primordials.d.ts‎

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type UncurryGetter<O, K extends keyof O, T = O> =
1919
typeUncurrySetter<O,KextendskeyofO,T=O>=
2020
O[K]extends infer V ? (self: T,value: V)=>void : never;
2121

22-
typeTypedArrayContentType<TextendsTypedArray>=Textends{[k: number]: infer V} ? V : never;
22+
typeTypedArrayContentType<TextendsTypedArrayConstructor>=InstanceType<T>[number];
2323

2424
/**
2525
* Primordials are a way to safely use globals without fear of global mutation
@@ -472,43 +472,30 @@ declare namespace primordials {
472472
exportconstSyntaxErrorPrototype: typeofSyntaxError.prototype
473473
exportimportTypeError=globalThis.TypeError;
474474
exportconstTypeErrorPrototype: typeofTypeError.prototype
475-
exportfunctionTypedArrayFrom<TextendsTypedArray>(
476-
constructor: new(length: number)=>T,
477-
source:
478-
|Iterable<TypedArrayContentType<T>>
479-
|ArrayLike<TypedArrayContentType<T>>,
480-
): T;
481-
exportfunctionTypedArrayFrom<TextendsTypedArray,U,THIS_ARG=undefined>(
482-
constructor: new(length: number)=>T,
475+
exportfunctionTypedArrayFrom<TextendsTypedArrayConstructor>(
476+
constructor: T,
477+
source: Iterable<TypedArrayContentType<T>>|ArrayLike<TypedArrayContentType<T>>,
478+
): InstanceType<T>
479+
exportfunctionTypedArrayFrom<TextendsTypedArrayConstructor,U,THIS_ARG=undefined>(
480+
constructor: T,
483481
source: Iterable<U>|ArrayLike<U>,
484482
mapfn: (
485483
this: THIS_ARG,
486484
value: U,
487485
index: number,
488486
)=>TypedArrayContentType<T>,
489487
thisArg?: THIS_ARG,
490-
): T;
491-
exportfunctionTypedArrayOf<TextendsTypedArray>(
492-
constructor: new(length: number)=>T,
493-
...items: readonlyTypedArrayContentType<T>[]
494-
): T;
495-
exportfunctionTypedArrayOfApply<TextendsTypedArray>(
496-
constructor: new(length: number)=>T,
488+
): InstanceType<T>;
489+
exportfunctionTypedArrayOf<TextendsTypedArrayConstructor>(
490+
constructor: T,
491+
...items: TypedArrayContentType<T>[],
492+
): InstanceType<T>;
493+
exportfunctionTypedArrayOfApply<TextendsTypedArrayConstructor>(
494+
constructor: T,
497495
items: readonlyTypedArrayContentType<T>[],
498-
): T;
499-
exportconstTypedArray: TypedArray;
500-
exportconstTypedArrayPrototype:
501-
|typeofUint8Array.prototype
502-
|typeofInt8Array.prototype
503-
|typeofUint16Array.prototype
504-
|typeofInt16Array.prototype
505-
|typeofUint32Array.prototype
506-
|typeofInt32Array.prototype
507-
|typeofFloat32Array.prototype
508-
|typeofFloat64Array.prototype
509-
|typeofBigInt64Array.prototype
510-
|typeofBigUint64Array.prototype
511-
|typeofUint8ClampedArray.prototype;
496+
): InstanceType<T>;
497+
exportconstTypedArray: TypedArrayConstructor;
498+
exportconstTypedArrayPrototype: TypedArrayConstructor["prototype"];
512499
exportconstTypedArrayPrototypeGetBuffer: UncurryGetter<TypedArray,"buffer">;
513500
exportconstTypedArrayPrototypeGetByteLength: UncurryGetter<TypedArray,"byteLength">;
514501
exportconstTypedArrayPrototypeGetByteOffset: UncurryGetter<TypedArray,"byteOffset">;
@@ -519,19 +506,7 @@ declare namespace primordials {
519506
exportfunctionTypedArrayPrototypeSet<TextendsTypedArray>(self: T, ...args: Parameters<T["set"]>): ReturnType<T["set"]>;
520507
exportfunctionTypedArrayPrototypeSubarray<TextendsTypedArray>(self: T, ...args: Parameters<T["subarray"]>): ReturnType<T["subarray"]>;
521508
exportfunctionTypedArrayPrototypeSlice<TextendsTypedArray>(self: T, ...args: Parameters<T["slice"]>): ReturnType<T["slice"]>;
522-
exportfunctionTypedArrayPrototypeGetSymbolToStringTag(self: unknown):
523-
|'Int8Array'
524-
|'Int16Array'
525-
|'Int32Array'
526-
|'Uint8Array'
527-
|'Uint16Array'
528-
|'Uint32Array'
529-
|'Uint8ClampedArray'
530-
|'BigInt64Array'
531-
|'BigUint64Array'
532-
|'Float32Array'
533-
|'Float64Array'
534-
|undefined;
509+
exportfunctionTypedArrayPrototypeGetSymbolToStringTag(self: unknown): TypedArray[typeofSymbol.toStringTag]|undefined;
535510
exportimportURIError=globalThis.URIError;
536511
exportconstURIErrorPrototype: typeofURIError.prototype
537512
exportimportUint16Array=globalThis.Uint16Array;

0 commit comments

Comments
 (0)