UNPKG

@visulima/inspector

Version:

Inspect utility for Node.js and Browsers.

76 lines (59 loc) 2.44 kB
/** Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive). @category Type */ type Primitive = | null | undefined | string | number | boolean | symbol | bigint; declare global { // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged. interface SymbolConstructor { readonly observable: symbol; } } /** Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union. Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals. This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore. @example ``` import type {LiteralUnion} from 'type-fest'; // Before type Pet = 'dog' | 'cat' | string; const pet: Pet = ''; // Start typing in your TypeScript-enabled IDE. // You **will not** get auto-completion for `dog` and `cat` literals. // After type Pet2 = LiteralUnion<'dog' | 'cat', string>; const pet: Pet2 = ''; // You **will** get auto-completion for `dog` and `cat` literals. ``` @category Type */ type LiteralUnion< LiteralType, BaseType extends Primitive, > = LiteralType | (BaseType & Record<never, never>); type Inspect = (input: unknown, options: Options) => string; interface Options { breakLength: number; customInspect: boolean; depth: number; indent: number | "\t" | undefined; maxArrayLength: number; numericSeparator: boolean; quoteStyle: "double" | "single"; showHidden: boolean; showProxy: boolean; stylize: <S extends string>(value: S, styleType: LiteralUnion<"bigint" | "boolean" | "date" | "null" | "number" | "regexp" | "special" | "string" | "symbol" | "undefined", string>) => string; truncate: number; } declare const inspect: (value: unknown, options_?: Partial<Options>) => string; declare const registerConstructor: (constructor: Function, inspector: Inspect) => boolean; declare const registerStringTag: (stringTag: string, inspector: Inspect) => boolean; export { type Options, inspect, registerConstructor, registerStringTag };