Extract nessessary types from type-fest

Signed-off-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
Richie Bendall 2020-07-20 08:21:03 +12:00
parent 8dd3a34bed
commit 1507a6db56
No known key found for this signature in database
GPG key ID: 94AE1ACB662A2A6D
3 changed files with 48 additions and 4 deletions

View file

@ -46,9 +46,6 @@
"typeguards",
"types"
],
"dependencies": {
"type-fest": "^0.16.0"
},
"devDependencies": {
"@sindresorhus/tsconfig": "^0.7.0",
"@types/jsdom": "^16.1.0",

View file

@ -2,7 +2,7 @@
/// <reference lib="dom"/>
/// <reference types="node"/>
import {Class, TypedArray, ObservableLike, Primitive} from 'type-fest';
import {Class, TypedArray, ObservableLike, Primitive} from './types';
const typedArrayTypeNames = [
'Int8Array',

47
source/types.ts Normal file
View file

@ -0,0 +1,47 @@
/**
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<T = unknown, Arguments extends any[] = any[]> = 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;
}