UNPKG

@xylabs/typeof

Version:

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

41 lines 2.19 kB
/** A value that can appear in a typed object tree (primitives, objects, arrays, functions, and symbols). */ export type TypedValue = bigint | string | number | boolean | null | TypedObject | TypedArray | Function | symbol | undefined; /** A valid key for a typed object. Defaults to string | number | symbol unless narrowed by T. */ export type TypedKey<T extends string | void = void> = T extends string ? T : string | number | symbol; /** An object whose keys are TypedKey and whose values are TypedValue. */ export type TypedObject = { [key: TypedKey]: TypedValue; } | object; /** An array of TypedValue elements. */ export type TypedArray = TypedValue[]; /** * Type guard that checks whether a value is a valid TypedKey (string, bigint, number, or symbol). * @param value - The value to check. * @returns True if the value is a valid TypedKey. */ export declare const isTypedKey: (value: unknown) => value is TypedKey; /** * Type guard that checks whether a value is a valid TypedValue. * @param value - The value to check. * @returns True if the value is a string, number, boolean, null, TypedObject, or TypedArray. */ export declare const isTypedValue: (value: unknown) => value is TypedValue; /** * Type guard that checks whether a value is a TypedArray (an array where every element is a TypedValue). * @param value - The value to check. * @returns True if the value is an array of TypedValue elements. */ export declare const isTypedArray: (value: unknown) => value is TypedArray; /** * Type guard that checks whether a key-value pair has a valid TypedKey and TypedValue. * @param pair - A tuple of [key, value] to validate. * @returns True if the key is a TypedKey and the value is a TypedValue. */ export declare const isValidTypedFieldPair: (pair: [key: unknown, value: unknown]) => pair is [key: TypedKey, value: TypedValue]; /** * Type guard that checks whether a value is a TypedObject (an object with TypedKey keys and TypedValue values). * @param value - The value to check. * @returns True if the value is a valid TypedObject. */ export declare const isTypedObject: (value: unknown) => value is TypedObject; //# sourceMappingURL=Typed.d.ts.map