turbodombuilder - v0.9.22
    Preparing search index...

    Type Alias SignalBox<Type>

    SignalBox: Type & SignalEntry<Type> & {
        toJSON(): Type;
        valueOf(): Type;
        value: Type;
        "[toPrimitive]"(hint: "string" | "number" | "default"): string | number;
    }

    Type Parameters

    • Type

    A signal entry that is also usable like its underlying primitive/object.

    • toJSON() returns the raw value.
    • valueOf() returns the raw value.
    • Symbol.toPrimitive(hint):
      • "number" → numeric coercion from the inner value
      • "string" or "default" → string coercion from the inner value
    • The value getter/setter mirrors get()/set() for ergonomic usage.
    const count: SignalBox<number> = signal(0);

    // Read
    console.log(count.get()); // 0
    console.log(count.value); // 0
    console.log(+count); // 0

    // Write
    count.set(5);
    count.value = 6;
    count.update(v => v + 1); // 7

    // JSON / string
    console.log(`${count}`); // "7"
    console.log(JSON.stringify(count)); // 7

    // Reactivity
    const unsub = count.sub(() => console.log("changed to", count.get()));
    count.set(8); // triggers subscriber
    unsub();