UNPKG

2.02 kBTypeScriptView Raw
1/// <reference lib="esnext"/>
2
3// TODO: This can just be `export type Primitive = not object` when the `not` keyword is out.
4/**
5Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
6*/
7export type Primitive =
8 | null
9 | undefined
10 | string
11 | number
12 | boolean
13 | symbol
14 | bigint;
15
16// TODO: Remove the `= unknown` sometime in the future when most users are on TS 3.5 as it's now the default
17/**
18Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
19*/
20export type Class<T = unknown, Arguments extends any[] = any[]> = new(...arguments_: Arguments) => T;
21
22/**
23Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
24*/
25export type TypedArray =
26 | Int8Array
27 | Uint8Array
28 | Uint8ClampedArray
29 | Int16Array
30 | Uint16Array
31 | Int32Array
32 | Uint32Array
33 | Float32Array
34 | Float64Array
35 | BigInt64Array
36 | BigUint64Array;
37
38/**
39Matches a JSON object.
40
41This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
42*/
43export type JsonObject = {[key: string]: JsonValue};
44
45/**
46Matches a JSON array.
47*/
48export interface JsonArray extends Array<JsonValue> {}
49
50/**
51Matches any valid JSON value.
52*/
53export type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
54
55declare global {
56 interface SymbolConstructor {
57 readonly observable: symbol;
58 }
59}
60
61/**
62Matches a value that is like an [Observable](https://github.com/tc39/proposal-observable).
63*/
64export interface ObservableLike {
65 subscribe(observer: (value: unknown) => void): void;
66 [Symbol.observable](): ObservableLike;
67}