@@ -8,12 +8,13 @@ var isTypedArray = require('is-typed-array');
88
99var typedArrays = require ( 'available-typed-arrays' ) ( ) ;
1010
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 */
1413
15- /** @type {Object.<TypedArrayNames, Getter> } */
16- var getters = { } ;
14+ /** @type {Partial<Record<TypedArrayName, Getter> & { __proto__: null }> } */
15+ var getters = {
16+ __proto__ : null
17+ } ;
1718
1819var oDP = Object . defineProperty ;
1920if ( gOPD ) {
@@ -24,7 +25,9 @@ if (gOPD) {
2425 forEach ( typedArrays , function ( typedArray ) {
2526 // In Safari 7, Typed Array constructors are typeof object
2627 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 ;
2831 // @ts -expect-error TS doesn't narrow properly inside callbacks
2932 var descriptor = gOPD ( Proto , 'byteLength' ) ;
3033 if ( ! descriptor && hasProto ) {
@@ -55,16 +58,20 @@ if (gOPD) {
5558/** @type {Getter } */
5659var tryTypedArrays = function tryAllTypedArrays ( value ) {
5760 /** @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+ }
6673 }
67- } ) ;
74+ ) ;
6875 // @ts -expect-error TS can't guarantee the callback is invoked sync
6976 return foundByteLength ;
7077} ;
0 commit comments