Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6c8fa42

Browse filesBrowse 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
Copy full SHA for 6c8fa42

2 files changed

+32-43Lines changed: 32 additions & 43 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎typings/globals.d.ts‎

Copy file name to clipboardExpand all lines: typings/globals.d.ts
+14Lines 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+
type TypedArrayConstructor =
91+
| typeof Uint8Array
92+
| typeof Uint8ClampedArray
93+
| typeof Uint16Array
94+
| typeof Uint32Array
95+
| typeof Int8Array
96+
| typeof Int16Array
97+
| typeof Int32Array
98+
| typeof Float16Array
99+
| typeof Float32Array
100+
| typeof Float64Array
101+
| typeof BigUint64Array
102+
| typeof BigInt64Array;
103+
90104
namespace NodeJS {
91105
interface Global {
92106
internalBinding<T extends InternalBindingKeys>(binding: T): InternalBindingMap[T]
Collapse file

‎typings/primordials.d.ts‎

Copy file name to clipboardExpand all lines: typings/primordials.d.ts
+18-43Lines 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
type UncurrySetter<O, K extends keyof O, T = O> =
2020
O[K] extends infer V ? (self: T, value: V) => void : never;
2121

22-
type TypedArrayContentType<T extends TypedArray> = T extends { [k: number]: infer V } ? V : never;
22+
type TypedArrayContentType<T extends TypedArrayConstructor> = 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
export const SyntaxErrorPrototype: typeof SyntaxError.prototype
473473
export import TypeError = globalThis.TypeError;
474474
export const TypeErrorPrototype: typeof TypeError.prototype
475-
export function TypedArrayFrom<T extends TypedArray>(
476-
constructor: new (length: number) => T,
477-
source:
478-
| Iterable<TypedArrayContentType<T>>
479-
| ArrayLike<TypedArrayContentType<T>>,
480-
): T;
481-
export function TypedArrayFrom<T extends TypedArray, U, THIS_ARG = undefined>(
482-
constructor: new (length: number) => T,
475+
export function TypedArrayFrom<T extends TypedArrayConstructor>(
476+
constructor: T,
477+
source: Iterable<TypedArrayContentType<T>> | ArrayLike<TypedArrayContentType<T>>,
478+
): InstanceType<T>
479+
export function TypedArrayFrom<T extends TypedArrayConstructor, 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-
export function TypedArrayOf<T extends TypedArray>(
492-
constructor: new (length: number) => T,
493-
...items: readonly TypedArrayContentType<T>[]
494-
): T;
495-
export function TypedArrayOfApply<T extends TypedArray>(
496-
constructor: new (length: number) => T,
488+
): InstanceType<T>;
489+
export function TypedArrayOf<T extends TypedArrayConstructor>(
490+
constructor: T,
491+
...items: TypedArrayContentType<T>[],
492+
): InstanceType<T>;
493+
export function TypedArrayOfApply<T extends TypedArrayConstructor>(
494+
constructor: T,
497495
items: readonly TypedArrayContentType<T>[],
498-
): T;
499-
export const TypedArray: TypedArray;
500-
export const TypedArrayPrototype:
501-
| typeof Uint8Array.prototype
502-
| typeof Int8Array.prototype
503-
| typeof Uint16Array.prototype
504-
| typeof Int16Array.prototype
505-
| typeof Uint32Array.prototype
506-
| typeof Int32Array.prototype
507-
| typeof Float32Array.prototype
508-
| typeof Float64Array.prototype
509-
| typeof BigInt64Array.prototype
510-
| typeof BigUint64Array.prototype
511-
| typeof Uint8ClampedArray.prototype;
496+
): InstanceType<T>;
497+
export const TypedArray: TypedArrayConstructor;
498+
export const TypedArrayPrototype: TypedArrayConstructor["prototype"];
512499
export const TypedArrayPrototypeGetBuffer: UncurryGetter<TypedArray, "buffer">;
513500
export const TypedArrayPrototypeGetByteLength: UncurryGetter<TypedArray, "byteLength">;
514501
export const TypedArrayPrototypeGetByteOffset: UncurryGetter<TypedArray, "byteOffset">;
@@ -519,19 +506,7 @@ declare namespace primordials {
519506
export function TypedArrayPrototypeSet<T extends TypedArray>(self: T, ...args: Parameters<T["set"]>): ReturnType<T["set"]>;
520507
export function TypedArrayPrototypeSubarray<T extends TypedArray>(self: T, ...args: Parameters<T["subarray"]>): ReturnType<T["subarray"]>;
521508
export function TypedArrayPrototypeSlice<T extends TypedArray>(self: T, ...args: Parameters<T["slice"]>): ReturnType<T["slice"]>;
522-
export function TypedArrayPrototypeGetSymbolToStringTag(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+
export function TypedArrayPrototypeGetSymbolToStringTag(self: unknown): TypedArray[typeof Symbol.toStringTag] | undefined;
535510
export import URIError = globalThis.URIError;
536511
export const URIErrorPrototype: typeof URIError.prototype
537512
export import Uint16Array = globalThis.Uint16Array;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.