-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.d.ts
More file actions
35 lines (29 loc) · 1.43 KB
/
Copy pathindex.d.ts
File metadata and controls
35 lines (29 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Determines the type of the given collection, or returns false.
*
* @param {unknown} value The potential collection
* @returns {TypedArrayName | false | null} 'Int8Array' | 'Uint8Array' | 'Uint8ClampedArray' | 'Int16Array' | 'Uint16Array' | 'Int32Array' | 'Uint32Array' | 'Float32Array' | 'Float64Array' | 'BigInt64Array' | 'BigUint64Array' | false | null
*/
declare function whichTypedArray<T>(value: T): false | null | whichTypedArray.WhichTypedArray<T>;
declare function whichTypedArray(value: unknown): false | null | whichTypedArray.TypedArrayName;
import TAs from 'available-typed-arrays';
declare namespace whichTypedArray {
export type TypedArrayName = ReturnType<typeof TAs>[number];
export type TypedArrayConstructor = typeof globalThis[TypedArrayName];
export type TypedArray = TypedArrayConstructor['prototype'];
/**
* Distributes over `T`, so a subset of typed arrays maps to the matching
* subset of names (`Int8Array | Uint8Array` -> `'Int8Array' | 'Uint8Array'`,
* never a float16 or bigint name). Any non-typed-array part adds `false | null`.
*
* Derived entirely from `TypedArrayName`, so a new entry in `available-typed-arrays` flows through with no other change here.
*/
export type WhichTypedArray<T> =
| {
[Name in TypedArrayName]: T extends typeof globalThis[Name]['prototype']
? Name
: never
}[TypedArrayName]
| ([T] extends [TypedArray] ? never : false | null);
}
export = whichTypedArray;