core / const

valueIsNonSignalObject

Checks whether a value is a non-signal object, optionally matching specific types.

Source: src/_core/utils/type-checkers.ts

Checks whether a value is a non-signal object, optionally matching specific types.

Signature

export const valueIsNonSignalObject = (
  input: any,
  shouldMatchAnyOfTypes?: string[],
): boolean =>
  input?.type === "non-signal" &&
  (!shouldMatchAnyOfTypes ||
    !shouldMatchAnyOfTypes.length ||
    shouldMatchAnyOfTypes.some((type) => typeof input?.value === type));

Parameters

(for example, ["string", "number"])

  • input: Any value to check
  • shouldMatchAnyOfTypes: Optional array of primitive type names to match

Returns

true if the value has type: "non-signal" and (if types provided) the value matches one of the types

Remarks

  • Empty types array is treated as no type restriction
  • Returns false for null and undefined

Examples

const nonSig = getNonSignalObject(42);
valueIsNonSignalObject(nonSig); // true
valueIsNonSignalObject(nonSig, ["number"]); // true
valueIsNonSignalObject(nonSig, ["string"]); // false

See Also

  • NonSignal - For non-signal type
  • getNonSignalObject - For creating non-signal objects