@@ -8,12 +8,13 @@ var isTypedArray = require('is-typed-array');
8
8
9
9
var typedArrays = require ( 'available-typed-arrays' ) ( ) ;
10
10
11
- /** @typedef {Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array } TypedArray */
12
- /** @typedef {import('possible-typed-array-names')[number] } TypedArrayNames */
13
- /** @typedef {(value: TypedArray) => number } Getter */
11
+ /** @typedef {import('possible-typed-array-names')[number] } TypedArrayName */
12
+ /** @typedef {(value: import('.').TypedArray) => number } Getter */
14
13
15
- /** @type {Object.<TypedArrayNames, Getter> } */
16
- var getters = { } ;
14
+ /** @type {Partial<Record<TypedArrayName, Getter> & { __proto__: null }> } */
15
+ var getters = {
16
+ __proto__ : null
17
+ } ;
17
18
18
19
var oDP = Object . defineProperty ;
19
20
if ( gOPD ) {
@@ -24,7 +25,9 @@ if (gOPD) {
24
25
forEach ( typedArrays , function ( typedArray ) {
25
26
// In Safari 7, Typed Array constructors are typeof object
26
27
if ( typeof global [ typedArray ] === 'function' || typeof global [ typedArray ] === 'object' ) {
27
- var Proto = global [ typedArray ] . prototype ;
28
+ var TA = global [ typedArray ] ;
29
+ /** @type {import('.').TypedArray } */
30
+ var Proto = TA . prototype ;
28
31
// @ts -expect-error TS doesn't narrow properly inside callbacks
29
32
var descriptor = gOPD ( Proto , 'byteLength' ) ;
30
33
if ( ! descriptor && hasProto ) {
@@ -55,16 +58,20 @@ if (gOPD) {
55
58
/** @type {Getter } */
56
59
var tryTypedArrays = function tryAllTypedArrays ( value ) {
57
60
/** @type {number } */ var foundByteLength ;
58
- forEach ( getters , /** @type {(getter: Getter) => void } */ function ( getter ) {
59
- if ( typeof foundByteLength !== 'number' ) {
60
- try {
61
- var byteLength = getter ( value ) ;
62
- if ( typeof byteLength === 'number' ) {
63
- foundByteLength = byteLength ;
64
- }
65
- } catch ( e ) { }
61
+ forEach (
62
+ // eslint-disable-next-line no-extra-parens
63
+ /** @type {Record<TypedArrayName, Getter> } */ ( getters ) ,
64
+ /** @type {(getter: Getter) => void } */ function ( getter ) {
65
+ if ( typeof foundByteLength !== 'number' ) {
66
+ try {
67
+ var byteLength = getter ( value ) ;
68
+ if ( typeof byteLength === 'number' ) {
69
+ foundByteLength = byteLength ;
70
+ }
71
+ } catch ( e ) { }
72
+ }
66
73
}
67
- } ) ;
74
+ ) ;
68
75
// @ts -expect-error TS can't guarantee the callback is invoked sync
69
76
return foundByteLength ;
70
77
} ;
0 commit comments