Skip to content

Commit 21f484f

Browse files
committed
[types] improve types
1 parent ad9cb70 commit 21f484f

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

Diff for: index.d.ts

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
type TypedArray =
2-
| Int8Array
3-
| Uint8Array
4-
| Uint8ClampedArray
5-
| Int16Array
6-
| Uint16Array
7-
| Int32Array
8-
| Uint32Array
9-
| Float32Array
10-
| Float64Array
11-
| BigInt64Array
12-
| BigUint64Array;
1+
import TypedArrayNames from 'possible-typed-array-names';
132

14-
declare function typedArrayByteOffset(value: TypedArray): number;
3+
declare namespace typedArrayByteOffset {
4+
export type TypedArrayName = typeof TypedArrayNames[number];
5+
6+
export type TypedArrayConstructor = typeof globalThis[TypedArrayName];
7+
8+
export type TypedArray = TypedArrayConstructor['prototype'];
9+
}
10+
11+
declare function typedArrayByteOffset(value: typedArrayByteOffset.TypedArray): number;
1512
declare function typedArrayByteOffset(value: unknown): false;
1613

1714
export = typedArrayByteOffset;

Diff for: index.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ var gPO = require('reflect.getprototypeof/polyfill')();
66

77
var typedArrays = require('available-typed-arrays')();
88

9-
/** @typedef {Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array} TypedArray */
10-
/** @typedef {(x: TypedArray) => number} ByteOffsetGetter */
9+
/** @typedef {(x: import('.').TypedArray) => number} ByteOffsetGetter */
1110

12-
/** @type {Object.<typeof typedArrays, ByteOffsetGetter>} */
13-
var getters = {};
11+
/** @type {Record<import('.').TypedArrayName, ByteOffsetGetter>} */
12+
var getters = {
13+
// @ts-expect-error TS can't handle __proto__ or `satisfies` in jsdoc
14+
__proto__: null
15+
};
1416

1517
var gOPD = require('gopd');
1618
var oDP = Object.defineProperty;

0 commit comments

Comments
 (0)