Skip to content

Reactive type

Home > @rimitive/signals > Reactive

Union type for any reactive value (readable or writable).

Use this when a function accepts either signals or computeds.

Signature:

export type Reactive<T> = Readable<T> | Writable<T>;

References: Readable, Writable

// Function that works with any reactive value
function double(source: Reactive<number>): Readable<number> {
return computed(() => source() * 2);
}
const count = signal(5);
const doubled = double(count); // Works with signal
const derived = computed(() => count() + 1);
const derivedDoubled = double(derived); // Works with computed too