diff --git a/source/index.ts b/source/index.ts index f819d82..ba578a4 100644 --- a/source/index.ts +++ b/source/index.ts @@ -2,7 +2,9 @@ /// /// -export type Class = new (...args: any[]) => T; +import {Class, TypedArray, ObservableLike, Primitive} from './types'; + +export {Class, TypedArray, ObservableLike, Primitive}; const typedArrayTypeNames = [ 'Int8Array', @@ -18,19 +20,6 @@ const typedArrayTypeNames = [ 'BigUint64Array' ] as const; -export type TypedArray = - | Int8Array - | Uint8Array - | Uint8ClampedArray - | Int16Array - | Uint16Array - | Int32Array - | Uint32Array - | Float32Array - | Float64Array - | BigInt64Array - | BigUint64Array; - type TypedArrayTypeName = typeof typedArrayTypeNames[number]; function isTypedArrayName(name: unknown): name is TypedArrayTypeName { @@ -80,15 +69,6 @@ const primitiveTypeNames = [ 'symbol' ] as const; -export type Primitive = - | null - | undefined - | string - | number - | bigint - | boolean - | symbol; - type PrimitiveTypeName = typeof primitiveTypeNames[number]; function isPrimitiveTypeName(name: unknown): name is PrimitiveTypeName { @@ -319,11 +299,6 @@ is.domElement = (value: unknown): value is HTMLElement => { DOM_PROPERTIES_TO_CHECK.every(property => property in value); }; -export interface ObservableLike { - subscribe(observer: (value: unknown) => void): void; - [Symbol.observable](): ObservableLike; -} - is.observable = (value: unknown): value is ObservableLike => { if (!value) { return false; diff --git a/source/types.ts b/source/types.ts new file mode 100644 index 0000000..8bdd0f5 --- /dev/null +++ b/source/types.ts @@ -0,0 +1,49 @@ +// Extracted from https://github.com/sindresorhus/type-fest/blob/78019f42ea888b0cdceb41a4a78163868de57555/index.d.ts + +/** +Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive). +*/ +export type Primitive = + | null + | undefined + | string + | number + | boolean + | symbol + | bigint; + +// TODO: Remove the `= unknown` sometime in the future when most users are on TS 3.5 as it's now the default +/** +Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes). +*/ +export type Class = new (...arguments_: Arguments) => T; + +/** +Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`. +*/ +export type TypedArray = + | Int8Array + | Uint8Array + | Uint8ClampedArray + | Int16Array + | Uint16Array + | Int32Array + | Uint32Array + | Float32Array + | Float64Array + | BigInt64Array + | BigUint64Array; + +declare global { + interface SymbolConstructor { + readonly observable: symbol; + } +} + +/** +Matches a value that is like an [Observable](https://github.com/tc39/proposal-observable). +*/ +export interface ObservableLike { + subscribe(observer: (value: unknown) => void): void; + [Symbol.observable](): ObservableLike; +}