import type { Branding } from "./Brand"; import type { Flavoring } from "./Flavor"; /** * This duplicates all the type implementations and expose them in the global * scope with a $ prefix. This will only modify the global scope if this /global * is imported by library user. */ declare global { /** * See the `Branding` type for details. */ type $MakeBranded = TypeToBrand & Branding; /** * Create strong 'branded' string, i.e. implicit string to branded type * conversion not allowed. */ type $MakeBrandedString = $MakeBranded; /** * Create strong 'branded' number, i.e. implicit number to branded type * conversion not allowed. */ type $MakeBrandedNumber = $MakeBranded; /** * See the `Flavoring` type for details. */ type $MakeFlavored = TypeToFlavor & Flavoring; /** * Create weak 'flavored' string, i.e. implicit string to flavored type * conversion allowed. */ type $MakeFlavoredString = $MakeFlavored; /** * Create weak 'flavored' number, i.e. implicit number to flavored type * conversion allowed. */ type $MakeFlavoredNumber = $MakeFlavored; /** * Deep version of `Partial` that will make all its keys and subkeys * optional. */ type $DeepPartial = T extends object ? { [P in keyof T]?: $DeepPartial; } : T; /** * Constrain Type to ensure that statically defined Array values are non-empty * containing at least one value. * * - `[]` is invalid * - `[T]` is valid * - `[T, T, T]` is valid */ type $NonEmptyArray = [T, ...T[]]; /** * Unions a given generic type with `null`. * * I.e. a `$Nullable` will become `T | null`. */ type $Nullable = T | null; /** * Unions a given generic type with `null` and `void` and `undefined`. * * Sometimes a value may or may not be provided, for e.g. like a function * parameter, and the same function parameter could also take in a `null` as a * valid value, in cases like these, this type can be helpful, but for most * use cases prefer `$Nullable` instead. * * I.e. a `$NullableAndOptional` will become `T | null | void | undefined`. */ type $NullableAndOptional = T | null | void | undefined; /** * Unions a given generic type with `void` and `undefined`. * * Sometimes a value may or may not be provided, for e.g. like a function * parameter, which is why this is called "optional", but for most use cases, * prefer `$Nullable` instead. * * I.e. a `$Optional` will become `T | void | undefined`. */ type $Optional = T | void | undefined; /** * Result tuple type encapsulates a result that could either be successful or * not successful. * * This is a 2 element tuple style that is inspired by Go's error handling * mechanism, where if there is an exception the tuple's first element will be * set and the second element will be null, and vice versa if no exception. * * This is a generic such that when it is successful, its type will be * the generic `TResult`, and if unsuccessful its types will be the generic * `TException`. * * You can then use TS type narrowing * ```typescript * const [exp, result] = myResultTuple * if (exp !== null){ * console.error('Operation failed with', exp); * return; * } * result; // Type narrowed to `TResult` * ``` * * Exception is always positioned first in the tuple so users are forced to * either handle it, or ignore it explicitly with something like `_`. * * `TException` extends `Exception` instead of `Error` to indicate that only * recoverable issues, i.e. exceptions not errors. * * This is the preferred way of handling Exceptions/Errors: * 1. Exceptions should be returned in `$ResultTuple` * 1. Errors (irrecoverable state) should be thrown * * However in reality, both Exceptions/Errors can be either returned in * `$ResultTuple` or thrown, just whichever is better for the specific * situation. But it is encouraged to stick to the preferred way which is why * the default TException type is `Exception`. */ type $ResultTuple = [null, TResult] | [TException, null]; } //# sourceMappingURL=global.d.ts.map