You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@xylabs/typeof

Package Overview
Dependencies
Maintainers
5
Versions
412
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xylabs/typeof

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

latest
Source
npmnpm
Version
5.0.86
Version published
Weekly downloads
13K
170.14%
Maintainers
5
Weekly downloads
 
Created
Source

@xylabs/typeof

logo

main-build npm-badge npm-downloads-badge jsdelivr-badge npm-license-badge codacy-badge codeclimate-badge snyk-badge socket-badge

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

Reference

@xylabs/typeof

Type Aliases

Type AliasDescription
BrandCreates a branded type by intersecting base type T with brand type B, enabling nominal typing in TypeScript.
IdentityFunctionA type guard function that narrows an unknown value to type T.
FieldTypeUnion of string literals representing the possible types of an object field.
ObjectTypeShapeDescribes the expected shape of an object by mapping each key to its expected field type.
TypeOfTypesUnion of string literals representing the possible results of the extended typeOf function.
TypedValueA value that can appear in a typed object tree (primitives, objects, arrays, functions, and symbols).
TypedKeyA valid key for a typed object. Defaults to string
TypedObjectAn object whose keys are TypedKey and whose values are TypedValue.
TypedArrayAn array of TypedValue elements.
AnyFunctionA function type that accepts any arguments and returns unknown.
RecordKeyA union of valid object key types.

Functions

FunctionDescription
isTypedKeyType guard that checks whether a value is a valid TypedKey (string, bigint, number, or symbol).
isTypedValueType guard that checks whether a value is a valid TypedValue.
isTypedArrayType guard that checks whether a value is a TypedArray (an array where every element is a TypedValue).
isValidTypedFieldPairType guard that checks whether a key-value pair has a valid TypedKey and TypedValue.
isTypedObjectType guard that checks whether a value is a TypedObject (an object with TypedKey keys and TypedValue values).
ifDefinedInvokes the callback only if the value is neither null nor undefined.
ifTypeOfInvokes the callback if the value matches the specified type, with an optional additional predicate.
isUndefinedType guard that checks whether a value is undefined.
isDefinedType guard that checks whether a value is not undefined.
isNullType guard that checks whether a value is null.
isDefinedNotNullType guard that checks whether a value is neither undefined nor null.
isUndefinedOrNullType guard that checks whether a value is undefined or null.
isBigIntType guard that checks whether a value is a bigint.
isStringType guard that checks whether a value is a string.
isNumberType guard that checks whether a value is a number.
isObjectType guard that checks whether a value is a plain object (not null and not an array).
isArrayType guard that checks whether a value is an array.
isFunctionType guard that checks whether a value is a function.
isSymbolType guard that checks whether a value is a symbol.
isEmptyObjectType guard that checks whether a value is an object with no own keys.
isEmptyStringType guard that checks whether a value is an empty string.
isEmptyArrayType guard that checks whether a value is an empty array.
isPopulatedArrayType guard that checks whether a value is a non-empty array.
isEmptyType guard that checks whether a value is empty (empty string, empty array, or empty object).
isFalsyType guard that checks whether a value is falsy (0, null, undefined, false, '', or 0n).
isTruthyType guard that checks whether a value is truthy (not 0, null, undefined, false, '', or 0n).
isBooleanType guard that checks whether a value is a boolean.
isDateStringType guard that checks whether a value is a string that can be parsed as a valid date.
isDateType guard that checks whether a value is a Date instance.
isRegExpType guard that checks whether a value is a RegExp instance.
isErrorType guard that checks whether a value is an Error instance.
isPromiseType guard that checks whether a value is a Promise instance.
isPromiseLikeType guard that checks whether a value is promise-like (has a then method).
isMapType guard that checks whether a value is a Map instance.
isArrayBufferViewType guard that checks whether a value is an ArrayBufferView (e.g., TypedArray or DataView).
isSetType guard that checks whether a value is a Set instance.
isWeakMapType guard that checks whether a value is a WeakMap instance.
isWeakSetType guard that checks whether a value is a WeakSet instance.
isDataViewType guard that checks whether a value is a DataView instance.
isBlobType guard that checks whether a value is a Blob instance.
isFileType guard that checks whether a value is a File instance.
isTypeChecks whether a value matches the expected field type, with correct handling for arrays and nulls.
typeOfExtended typeof that distinguishes arrays from objects (unlike native typeof).
validateTypeValidates that a value matches the expected type, returning the value and any errors.

functions

ifDefined

@xylabs/typeof

function ifDefined<T>(value: T, func: (value: T) => void): T | undefined;

Invokes the callback only if the value is neither null nor undefined.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
valueTThe value to check.
func(value: T) => voidThe callback to invoke with the value if it is defined.

Returns

T | undefined

The value if defined, or undefined otherwise.

ifTypeOf

@xylabs/typeof

function ifTypeOf<T, R>(
   typeName: TypeOfTypes, 
   value: unknown, 
   trueFunc: (value: T) => R, 
   isFunc?: (value: T) => boolean): R | undefined;

Invokes the callback if the value matches the specified type, with an optional additional predicate.

Type Parameters

Type Parameter
T
R

Parameters

ParameterTypeDescription
typeNameTypeOfTypesThe expected type name to match against.
valueunknownThe value to check.
trueFunc(value: T) => RThe callback to invoke if the type matches.
isFunc?(value: T) => booleanOptional additional predicate that must also return true.

Returns

R | undefined

The result of trueFunc if the type matches (and isFunc passes), or undefined.

isArray

@xylabs/typeof

Call Signature

function isArray(value: unknown): value is readonly unknown[];

Type guard that checks whether a value is an array.

Parameters

ParameterType
valueunknown

Returns

value is readonly unknown[]

Call Signature

function isArray<T>(value: T): value is Extract<T, readonly unknown[]>;

Type guard that checks whether a value is an array.

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

value is Extract<T, readonly unknown[]>

isArrayBufferView

@xylabs/typeof

Call Signature

function isArrayBufferView(value: unknown): value is ArrayBufferView<ArrayBufferLike>;

Type guard that checks whether a value is an ArrayBufferView (e.g., TypedArray or DataView).

Parameters

ParameterType
valueunknown

Returns

value is ArrayBufferView<ArrayBufferLike>

Call Signature

function isArrayBufferView<T>(value: T): value is Extract<T, ArrayBufferView<ArrayBufferLike>>;

Type guard that checks whether a value is an ArrayBufferView (e.g., TypedArray or DataView).

Type Parameters

Type Parameter
T extends ArrayBufferView<ArrayBufferLike>

Parameters

ParameterType
valueT

Returns

value is Extract<T, ArrayBufferView<ArrayBufferLike>>

isBigInt

@xylabs/typeof

Call Signature

function isBigInt(value: unknown): value is bigint;

Type guard that checks whether a value is a bigint.

Parameters

ParameterType
valueunknown

Returns

value is bigint

Call Signature

function isBigInt<T>(value: T): value is Extract<T, bigint>;

Type guard that checks whether a value is a bigint.

Type Parameters

Type Parameter
T extends bigint

Parameters

ParameterType
valueT

Returns

value is Extract<T, bigint>

isBlob

@xylabs/typeof

Call Signature

function isBlob(value: unknown): value is Blob;

Type guard that checks whether a value is a Blob instance.

Parameters

ParameterType
valueunknown

Returns

value is Blob

Call Signature

function isBlob<T>(value: T): value is Extract<T, Blob>;

Type guard that checks whether a value is a Blob instance.

Type Parameters

Type Parameter
T extends Blob

Parameters

ParameterType
valueT

Returns

value is Extract<T, Blob>

isBoolean

@xylabs/typeof

Call Signature

function isBoolean(value: unknown): value is boolean;

Type guard that checks whether a value is a boolean.

Parameters

ParameterType
valueunknown

Returns

value is boolean

Call Signature

function isBoolean<T>(value: T): value is Extract<T, boolean>;

Type guard that checks whether a value is a boolean.

Type Parameters

Type Parameter
T extends boolean

Parameters

ParameterType
valueT

Returns

value is Extract<T, boolean>

isDataView

@xylabs/typeof

Call Signature

function isDataView(value: unknown): value is DataView<ArrayBufferLike>;

Type guard that checks whether a value is a DataView instance.

Parameters

ParameterType
valueunknown

Returns

value is DataView<ArrayBufferLike>

Call Signature

function isDataView<T>(value: T): value is Extract<T, DataView<ArrayBufferLike>>;

Type guard that checks whether a value is a DataView instance.

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

value is Extract<T, DataView<ArrayBufferLike>>

isDate

@xylabs/typeof

Call Signature

function isDate(value: unknown): value is Date;

Type guard that checks whether a value is a Date instance.

Parameters

ParameterType
valueunknown

Returns

value is Date

Call Signature

function isDate<T>(value: T): value is Extract<T, Date>;

Type guard that checks whether a value is a Date instance.

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

value is Extract<T, Date>

isDateString

@xylabs/typeof

Call Signature

function isDateString(value: unknown): value is string;

Type guard that checks whether a value is a string that can be parsed as a valid date.

Parameters

ParameterType
valueunknown

Returns

value is string

Call Signature

function isDateString<T>(value: T): value is Extract<T, string>;

Type guard that checks whether a value is a string that can be parsed as a valid date.

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

value is Extract<T, string>

isDefined

@xylabs/typeof

function isDefined<T>(value: T): value is Exclude<T, undefined>;

Type guard that checks whether a value is not undefined.

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

value is Exclude<T, undefined>

isDefinedNotNull

@xylabs/typeof

function isDefinedNotNull<T>(value: T): value is Exclude<T, null | undefined>;

Type guard that checks whether a value is neither undefined nor null.

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

value is Exclude<T, null | undefined>

isEmpty

@xylabs/typeof

Call Signature

function isEmpty<T>(value: unknown): value is T;

Type guard that checks whether a value is empty (empty string, empty array, or empty object).

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueunknown

Returns

value is T

Call Signature

function isEmpty<K, V, T>(value: T): value is Extract<T, Record<K, never>>;

Type guard that checks whether a value is empty (empty string, empty array, or empty object).

Type Parameters

Type Parameter
K extends RecordKey
V
T extends Record<K, V>

Parameters

ParameterType
valueT

Returns

value is Extract<T, Record<K, never>>

Call Signature

function isEmpty<T>(value: T): value is Extract<T, never[]>;

Type guard that checks whether a value is empty (empty string, empty array, or empty object).

Type Parameters

Type Parameter
T extends unknown[]

Parameters

ParameterType
valueT

Returns

value is Extract<T, never[]>

isEmptyArray

@xylabs/typeof

Call Signature

function isEmptyArray(value: unknown): value is [];

Type guard that checks whether a value is an empty array.

Parameters

ParameterType
valueunknown

Returns

value is []

Call Signature

function isEmptyArray<T>(value: T): value is Extract<T, unknown[]>;

Type guard that checks whether a value is an empty array.

Type Parameters

Type Parameter
T extends unknown[]

Parameters

ParameterType
valueT

Returns

value is Extract<T, unknown[]>

isEmptyObject

@xylabs/typeof

Call Signature

function isEmptyObject(value: unknown): value is {};

Type guard that checks whether a value is an object with no own keys.

Parameters

ParameterType
valueunknown

Returns

value is {}

Call Signature

function isEmptyObject<K, V, T>(value: T): value is Extract<T, Record<K, never>>;

Type guard that checks whether a value is an object with no own keys.

Type Parameters

Type Parameter
K extends RecordKey
V
T extends Record<K, V>

Parameters

ParameterType
valueT

Returns

value is Extract<T, Record<K, never>>

isEmptyString

@xylabs/typeof

Call Signature

function isEmptyString(value: unknown): value is "";

Type guard that checks whether a value is an empty string.

Parameters

ParameterType
valueunknown

Returns

value is ""

Call Signature

function isEmptyString<T>(value: T): value is Extract<T, "">;

Type guard that checks whether a value is an empty string.

Type Parameters

Type Parameter
T extends string

Parameters

ParameterType
valueT

Returns

value is Extract<T, "">

isError

@xylabs/typeof

Call Signature

function isError(value: unknown): value is Error;

Type guard that checks whether a value is an Error instance.

Parameters

ParameterType
valueunknown

Returns

value is Error

Call Signature

function isError<T>(value: T): value is Extract<T, Error>;

Type guard that checks whether a value is an Error instance.

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

value is Extract<T, Error>

isFalsy

@xylabs/typeof

Call Signature

function isFalsy<T>(value: T): value is Extract<T, false | "" | 0 | 0n | null | undefined>;

Type guard that checks whether a value is falsy (0, null, undefined, false, '', or 0n).

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

value is Extract<T, false | "" | 0 | 0n | null | undefined>

Call Signature

function isFalsy<T>(value: T): value is Extract<T, false>;

Type guard that checks whether a value is falsy (0, null, undefined, false, '', or 0n).

Type Parameters

Type Parameter
T extends boolean

Parameters

ParameterType
valueT

Returns

value is Extract<T, false>

Call Signature

function isFalsy<T>(value: T): value is Extract<T, 0>;

Type guard that checks whether a value is falsy (0, null, undefined, false, '', or 0n).

Type Parameters

Type Parameter
T extends number

Parameters

ParameterType
valueT

Returns

value is Extract<T, 0>

Call Signature

function isFalsy<T>(value: T): value is Extract<T, 0n>;

Type guard that checks whether a value is falsy (0, null, undefined, false, '', or 0n).

Type Parameters

Type Parameter
T extends bigint

Parameters

ParameterType
valueT

Returns

value is Extract<T, 0n>

Call Signature

function isFalsy<T>(value: T): value is Extract<T, null>;

Type guard that checks whether a value is falsy (0, null, undefined, false, '', or 0n).

Type Parameters

Type Parameter
T extends null

Parameters

ParameterType
valueT

Returns

value is Extract<T, null>

Call Signature

function isFalsy<T>(value: T): value is Extract<T, undefined>;

Type guard that checks whether a value is falsy (0, null, undefined, false, '', or 0n).

Type Parameters

Type Parameter
T extends undefined

Parameters

ParameterType
valueT

Returns

value is Extract<T, undefined>

Call Signature

function isFalsy<T>(value: T): value is Extract<T, "">;

Type guard that checks whether a value is falsy (0, null, undefined, false, '', or 0n).

Type Parameters

Type Parameter
T extends string

Parameters

ParameterType
valueT

Returns

value is Extract<T, "">

isFile

@xylabs/typeof

Call Signature

function isFile(value: unknown): value is File;

Type guard that checks whether a value is a File instance.

Parameters

ParameterType
valueunknown

Returns

value is File

Call Signature

function isFile<T>(value: T): value is Extract<T, File>;

Type guard that checks whether a value is a File instance.

Type Parameters

Type Parameter
T extends File

Parameters

ParameterType
valueT

Returns

value is Extract<T, File>

isFunction

@xylabs/typeof

Call Signature

function isFunction(value: unknown): value is AnyFunction;

Type guard that checks whether a value is a function.

Parameters

ParameterType
valueunknown

Returns

value is AnyFunction

Call Signature

function isFunction<T>(value: T): value is Extract<T, AnyFunction>;

Type guard that checks whether a value is a function.

Type Parameters

Type Parameter
T extends AnyFunction

Parameters

ParameterType
valueT

Returns

value is Extract<T, AnyFunction>

isMap

@xylabs/typeof

Call Signature

function isMap(value: unknown): value is Map<unknown, unknown>;

Type guard that checks whether a value is a Map instance.

Parameters

ParameterType
valueunknown

Returns

value is Map<unknown, unknown>

Call Signature

function isMap<K, V, T>(value: T): value is Extract<T, Map<K, V>>;

Type guard that checks whether a value is a Map instance.

Type Parameters

Type Parameter
K
V
T extends Map<K, V>

Parameters

ParameterType
valueT

Returns

value is Extract<T, Map<K, V>>

isNull

@xylabs/typeof

Call Signature

function isNull(value: unknown): value is null;

Type guard that checks whether a value is null.

Parameters

ParameterType
valueunknown

Returns

value is null

Call Signature

function isNull<T>(value: T): value is Extract<T, null>;

Type guard that checks whether a value is null.

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

value is Extract<T, null>

isNumber

@xylabs/typeof

Call Signature

function isNumber(value: unknown): value is number;

Type guard that checks whether a value is a number.

Parameters

ParameterType
valueunknown

Returns

value is number

Call Signature

function isNumber<T>(value: T): value is Extract<T, number>;

Type guard that checks whether a value is a number.

Type Parameters

Type Parameter
T extends number

Parameters

ParameterType
valueT

Returns

value is Extract<T, number>

isObject

@xylabs/typeof

Call Signature

function isObject(value: unknown): value is object;

Type guard that checks whether a value is a plain object (not null and not an array).

Parameters

ParameterType
valueunknown

Returns

value is object

Call Signature

function isObject<T>(value: T): value is Extract<T, object>;

Type guard that checks whether a value is a plain object (not null and not an array).

Type Parameters

Type Parameter
T extends object

Parameters

ParameterType
valueT

Returns

value is Extract<T, object>

isPopulatedArray

@xylabs/typeof

Call Signature

function isPopulatedArray(value: unknown): value is readonly unknown[];

Type guard that checks whether a value is a non-empty array.

Parameters

ParameterType
valueunknown

Returns

value is readonly unknown[]

Call Signature

function isPopulatedArray<T>(value: T): value is Extract<T, readonly unknown[]>;

Type guard that checks whether a value is a non-empty array.

Type Parameters

Type Parameter
T extends unknown[]

Parameters

ParameterType
valueT

Returns

value is Extract<T, readonly unknown[]>

isPromise

@xylabs/typeof

Call Signature

function isPromise(value: unknown): value is Promise<unknown>;

Type guard that checks whether a value is a Promise instance.

Parameters

ParameterType
valueunknown

Returns

value is Promise<unknown>

Call Signature

function isPromise<T>(value: T): value is Extract<T, Promise<unknown>>;

Type guard that checks whether a value is a Promise instance.

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

value is Extract<T, Promise<unknown>>

isPromiseLike

@xylabs/typeof

Call Signature

function isPromiseLike(value: unknown): value is Promise<unknown>;

Type guard that checks whether a value is promise-like (has a then method).

Parameters

ParameterType
valueunknown

Returns

value is Promise<unknown>

Call Signature

function isPromiseLike<T>(value: T): value is Extract<T, Promise<unknown>>;

Type guard that checks whether a value is promise-like (has a then method).

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

value is Extract<T, Promise<unknown>>

isRegExp

@xylabs/typeof

Call Signature

function isRegExp(value: unknown): value is RegExp;

Type guard that checks whether a value is a RegExp instance.

Parameters

ParameterType
valueunknown

Returns

value is RegExp

Call Signature

function isRegExp<T>(value: T): value is Extract<T, RegExp>;

Type guard that checks whether a value is a RegExp instance.

Type Parameters

Type Parameter
T extends RegExp

Parameters

ParameterType
valueT

Returns

value is Extract<T, RegExp>

isSet

@xylabs/typeof

Call Signature

function isSet(value: unknown): value is Set<unknown>;

Type guard that checks whether a value is a Set instance.

Parameters

ParameterType
valueunknown

Returns

value is Set<unknown>

Call Signature

function isSet<T>(value: unknown): value is Extract<T, Set<unknown>>;

Type guard that checks whether a value is a Set instance.

Type Parameters

Type Parameter
T extends Set<unknown>

Parameters

ParameterType
valueunknown

Returns

value is Extract<T, Set<unknown>>

isString

@xylabs/typeof

Call Signature

function isString(value: unknown): value is string;

Type guard that checks whether a value is a string.

Parameters

ParameterType
valueunknown

Returns

value is string

Call Signature

function isString<T>(value: T): value is Extract<T, string>;

Type guard that checks whether a value is a string.

Type Parameters

Type Parameter
T extends string

Parameters

ParameterType
valueT

Returns

value is Extract<T, string>

isSymbol

@xylabs/typeof

Call Signature

function isSymbol(value: unknown): value is symbol;

Type guard that checks whether a value is a symbol.

Parameters

ParameterType
valueunknown

Returns

value is symbol

Call Signature

function isSymbol<T>(value: T): value is Extract<T, symbol>;

Type guard that checks whether a value is a symbol.

Type Parameters

Type Parameter
T extends symbol

Parameters

ParameterType
valueT

Returns

value is Extract<T, symbol>

isTruthy

@xylabs/typeof

Call Signature

function isTruthy<T>(value: T): value is Exclude<T, false | "" | 0 | 0n | null | undefined>;

Type guard that checks whether a value is truthy (not 0, null, undefined, false, '', or 0n).

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

value is Exclude<T, false | "" | 0 | 0n | null | undefined>

Call Signature

function isTruthy<T>(value: T): value is Extract<T, true>;

Type guard that checks whether a value is truthy (not 0, null, undefined, false, '', or 0n).

Type Parameters

Type Parameter
T extends boolean

Parameters

ParameterType
valueT

Returns

value is Extract<T, true>

Call Signature

function isTruthy<T>(value: T): value is Extract<T, number>;

Type guard that checks whether a value is truthy (not 0, null, undefined, false, '', or 0n).

Type Parameters

Type Parameter
T extends number

Parameters

ParameterType
valueT

Returns

value is Extract<T, number>

Call Signature

function isTruthy<T>(value: T): value is Extract<T, bigint>;

Type guard that checks whether a value is truthy (not 0, null, undefined, false, '', or 0n).

Type Parameters

Type Parameter
T extends bigint

Parameters

ParameterType
valueT

Returns

value is Extract<T, bigint>

Call Signature

function isTruthy<T>(value: T): value is Extract<T, null>;

Type guard that checks whether a value is truthy (not 0, null, undefined, false, '', or 0n).

Type Parameters

Type Parameter
T extends null

Parameters

ParameterType
valueT

Returns

value is Extract<T, null>

Call Signature

function isTruthy<T>(value: T): value is Extract<T, undefined>;

Type guard that checks whether a value is truthy (not 0, null, undefined, false, '', or 0n).

Type Parameters

Type Parameter
T extends undefined

Parameters

ParameterType
valueT

Returns

value is Extract<T, undefined>

Call Signature

function isTruthy<T>(value: T): value is Extract<T, string>;

Type guard that checks whether a value is truthy (not 0, null, undefined, false, '', or 0n).

Type Parameters

Type Parameter
T extends string

Parameters

ParameterType
valueT

Returns

value is Extract<T, string>

isType

@xylabs/typeof

function isType(value: unknown, expectedType: FieldType): boolean;

Checks whether a value matches the expected field type, with correct handling for arrays and nulls.

Parameters

ParameterTypeDescription
valueunknownThe value to check.
expectedTypeFieldTypeThe expected type string.

Returns

boolean

True if the value matches the expected type.

isTypedArray

@xylabs/typeof

function isTypedArray(value: unknown): value is TypedArray;

Type guard that checks whether a value is a TypedArray (an array where every element is a TypedValue).

Parameters

ParameterTypeDescription
valueunknownThe value to check.

Returns

value is TypedArray

True if the value is an array of TypedValue elements.

isTypedKey

@xylabs/typeof

function isTypedKey(value: unknown): value is string | number | symbol;

Type guard that checks whether a value is a valid TypedKey (string, bigint, number, or symbol).

Parameters

ParameterTypeDescription
valueunknownThe value to check.

Returns

value is string | number | symbol

True if the value is a valid TypedKey.

isTypedObject

@xylabs/typeof

function isTypedObject(value: unknown): value is TypedObject;

Type guard that checks whether a value is a TypedObject (an object with TypedKey keys and TypedValue values).

Parameters

ParameterTypeDescription
valueunknownThe value to check.

Returns

value is TypedObject

True if the value is a valid TypedObject.

isTypedValue

@xylabs/typeof

function isTypedValue(value: unknown): value is TypedValue;

Type guard that checks whether a value is a valid TypedValue.

Parameters

ParameterTypeDescription
valueunknownThe value to check.

Returns

value is TypedValue

True if the value is a string, number, boolean, null, TypedObject, or TypedArray.

isUndefined

@xylabs/typeof

Call Signature

function isUndefined(value: unknown): value is undefined;

Type guard that checks whether a value is undefined.

Parameters

ParameterType
valueunknown

Returns

value is undefined

Call Signature

function isUndefined<T>(value: T): value is Extract<T, undefined>;

Type guard that checks whether a value is undefined.

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

value is Extract<T, undefined>

isUndefinedOrNull

@xylabs/typeof

Call Signature

function isUndefinedOrNull(value: unknown): value is null | undefined;

Type guard that checks whether a value is undefined or null.

Parameters

ParameterType
valueunknown

Returns

value is null | undefined

Call Signature

function isUndefinedOrNull<T>(value: T): value is Extract<T, null | undefined>;

Type guard that checks whether a value is undefined or null.

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueT

Returns

value is Extract<T, null | undefined>

isValidTypedFieldPair

@xylabs/typeof

function isValidTypedFieldPair(pair: [unknown, unknown]): pair is [key: string | number | symbol, value: TypedValue];

Type guard that checks whether a key-value pair has a valid TypedKey and TypedValue.

Parameters

ParameterTypeDescription
pair[unknown, unknown]A tuple of [key, value] to validate.

Returns

pair is [key: string | number | symbol, value: TypedValue]

True if the key is a TypedKey and the value is a TypedValue.

isWeakMap

@xylabs/typeof

Call Signature

function isWeakMap(value: unknown): value is WeakMap<WeakKey, unknown>;

Type guard that checks whether a value is a WeakMap instance.

Parameters

ParameterType
valueunknown

Returns

value is WeakMap<WeakKey, unknown>

Call Signature

function isWeakMap<K, V, T>(value: T): value is Extract<T, WeakMap<K, V>>;

Type guard that checks whether a value is a WeakMap instance.

Type Parameters

Type Parameter
K extends WeakKey
V
T extends WeakMap<K, V>

Parameters

ParameterType
valueT

Returns

value is Extract<T, WeakMap<K, V>>

isWeakSet

@xylabs/typeof

Call Signature

function isWeakSet(value: unknown): value is WeakSet<WeakKey>;

Type guard that checks whether a value is a WeakSet instance.

Parameters

ParameterType
valueunknown

Returns

value is WeakSet<WeakKey>

Call Signature

function isWeakSet<K, T>(value: T): value is Extract<T, WeakSet<K>>;

Type guard that checks whether a value is a WeakSet instance.

Type Parameters

Type Parameter
K extends WeakKey
T extends WeakSet<K>

Parameters

ParameterType
valueT

Returns

value is Extract<T, WeakSet<K>>

typeOf

@xylabs/typeof

function typeOf<T>(item: T): TypeOfTypes;

Extended typeof that distinguishes arrays from objects (unlike native typeof).

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
itemTThe value to check.

Returns

TypeOfTypes

The type of the item as a TypeOfTypes string.

validateType

@xylabs/typeof

function validateType<T>(
   typeName: TypeOfTypes, 
   value: T, 
   optional?: boolean): [T | undefined, Error[]];

Validates that a value matches the expected type, returning the value and any errors.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDefault valueDescription
typeNameTypeOfTypesundefinedThe expected type name.
valueTundefinedThe value to validate.
optionalbooleanfalseIf true, undefined values are accepted without error.

Returns

[T | undefined, Error[]]

A tuple of [value or undefined, array of errors].

type-aliases

AnyFunction

@xylabs/typeof

type AnyFunction = (...args: unknown[]) => unknown;

A function type that accepts any arguments and returns unknown.

Parameters

ParameterType
...argsunknown[]

Returns

unknown

Brand

@xylabs/typeof

type Brand<T, B> = T & { [K in keyof B]: B[K] };

Creates a branded type by intersecting base type T with brand type B, enabling nominal typing in TypeScript.

Type Parameters

Type Parameter
T
B

FieldType

@xylabs/typeof

type FieldType = 
  | "string"
  | "number"
  | "object"
  | "symbol"
  | "undefined"
  | "null"
  | "array"
  | "function";

Union of string literals representing the possible types of an object field.

IdentityFunction

@xylabs/typeof

type IdentityFunction<T> = (value: unknown) => value is T;

A type guard function that narrows an unknown value to type T.

Type Parameters

Type Parameter
T

Parameters

ParameterType
valueunknown

Returns

value is T

ObjectTypeShape

@xylabs/typeof

type ObjectTypeShape = Record<string | number | symbol, FieldType>;

Describes the expected shape of an object by mapping each key to its expected field type.

RecordKey

@xylabs/typeof

type RecordKey = string | number | symbol;

A union of valid object key types.

TypeOfTypes

@xylabs/typeof

type TypeOfTypes = 
  | "string"
  | "number"
  | "object"
  | "array"
  | "buffer"
  | "null"
  | "undefined"
  | "bigint"
  | "boolean"
  | "function"
  | "symbol";

Union of string literals representing the possible results of the extended typeOf function.

TypedArray

@xylabs/typeof

type TypedArray = TypedValue[];

An array of TypedValue elements.

TypedKey

@xylabs/typeof

type TypedKey<T> = T extends string ? T : string | number | symbol;

A valid key for a typed object. Defaults to string | number | symbol unless narrowed by T.

Type Parameters

Type ParameterDefault type
T extends string | voidvoid

TypedObject

@xylabs/typeof

type TypedObject = 
  | {
[key: string | number | symbol]: TypedValue;
}
  | object;

An object whose keys are TypedKey and whose values are TypedValue.

TypedValue

@xylabs/typeof

type TypedValue = 
  | bigint
  | string
  | number
  | boolean
  | null
  | TypedObject
  | TypedArray
  | Function
  | symbol
  | undefined;

A value that can appear in a typed object tree (primitives, objects, arrays, functions, and symbols).

Part of sdk-js

Maintainers

License

See the LICENSE file for license details

Credits

Made with 🔥 and ❄️ by XYLabs

Keywords

typeof

FAQs

Package last updated on 11 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts