Split TypeNames and Types into different lists
This commit is contained in:
parent
6824f1446d
commit
dc348a0e49
1 changed files with 50 additions and 30 deletions
|
|
@ -31,42 +31,62 @@ const objectTypeNames = [
|
||||||
|
|
||||||
type ObjectTypeName = typeof objectTypeNames[number];
|
type ObjectTypeName = typeof objectTypeNames[number];
|
||||||
|
|
||||||
const primitives = {
|
const primitiveTypeNames = [
|
||||||
null: null,
|
'null',
|
||||||
undefined,
|
'undefined',
|
||||||
string: String(),
|
'string',
|
||||||
number: Number(),
|
'number',
|
||||||
bigint: BigInt(0),
|
'bigint',
|
||||||
boolean: Boolean(),
|
'boolean',
|
||||||
symbol: Symbol('')
|
'symbol'
|
||||||
} as const;
|
] as const;
|
||||||
|
|
||||||
type PrimitiveTypeName = keyof typeof primitives;
|
export type Primitive =
|
||||||
export type Primitive = typeof primitives[PrimitiveTypeName];
|
| null
|
||||||
|
| undefined
|
||||||
|
| string
|
||||||
|
| number
|
||||||
|
| bigint
|
||||||
|
| boolean
|
||||||
|
| symbol;
|
||||||
|
|
||||||
function isPrimitiveTypeName(name: string): name is PrimitiveTypeName {
|
type PrimitiveTypeName = typeof primitiveTypeNames[number];
|
||||||
return Object.prototype.hasOwnProperty.call(primitives, name);
|
|
||||||
|
function isPrimitiveTypeName(name: any): name is PrimitiveTypeName {
|
||||||
|
return primitiveTypeNames.includes(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
const typedArrays = {
|
const typedArrayTypeNames = [
|
||||||
Int8Array: new Int8Array(),
|
'Int8Array',
|
||||||
Uint8Array: new Uint8Array(),
|
'Uint8Array',
|
||||||
Uint8ClampedArray: new Uint8ClampedArray(),
|
'Uint8ClampedArray',
|
||||||
Int16Array: new Int16Array(),
|
'Int16Array',
|
||||||
Uint16Array: new Uint16Array(),
|
'Uint16Array',
|
||||||
Int32Array: new Int32Array(),
|
'Int32Array',
|
||||||
Uint32Array: new Uint32Array(),
|
'Uint32Array',
|
||||||
Float32Array: new Float32Array(),
|
'Float32Array',
|
||||||
Float64Array: new Float64Array(),
|
'Float64Array',
|
||||||
BigInt64Array: new BigInt64Array(),
|
'BigInt64Array',
|
||||||
BigUint64Array: new BigUint64Array()
|
'BigUint64Array'
|
||||||
} as const;
|
] as const;
|
||||||
|
|
||||||
type TypedArrayTypeName = keyof typeof typedArrays;
|
export type TypedArray =
|
||||||
export type TypedArray = typeof typedArrays[TypedArrayTypeName];
|
| Int8Array
|
||||||
|
| Uint8Array
|
||||||
|
| Uint8ClampedArray
|
||||||
|
| Int16Array
|
||||||
|
| Uint16Array
|
||||||
|
| Int32Array
|
||||||
|
| Uint32Array
|
||||||
|
| Float32Array
|
||||||
|
| Float64Array
|
||||||
|
| BigInt64Array
|
||||||
|
| BigUint64Array;
|
||||||
|
|
||||||
function isTypedArrayName(value: any): value is TypedArrayTypeName {
|
type TypedArrayTypeName = typeof typedArrayTypeNames[number];
|
||||||
return Object.prototype.hasOwnProperty.call(typedArrays, value);
|
|
||||||
|
function isTypedArrayName(name: any): name is TypedArrayTypeName {
|
||||||
|
return typedArrayTypeNames.includes(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TypeName = ObjectTypeName | PrimitiveTypeName | TypedArrayTypeName;
|
export type TypeName = ObjectTypeName | PrimitiveTypeName | TypedArrayTypeName;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue