What type a derived signal should be?
just
() => boolean
or Accessor<boolean>
?7 Replies
They are the same. Accessor is just
export type Accessor<T> = () => T;
I mostly don't type derived signals and let typescript infer it
const doubleCount = () => count() * 2
And typescript knows it's () => number
I know, but I'm asking about good practices. A derived signal is not defined using
createSignal
, so using Accessor
seems not the best idea – OTOH, it is a signal
I need to type it, because I pass it as a prop to a component
and I want to type the propsIt's really up to you. You don't get any benefits from typing it
Accessor
apart from different naming when hovering over the property. If you like it when they are named like that for clarity, go for it!no createSignal<T>() must be typed by Signal<T> as best practice, imo.
we're talking about derived signals, which are just functions
oh you mean memo , so createMemo must be typed with Accessor for extra clarity.
no memos are something different
https://docs.solidjs.com/concepts/derived-values/derived-signals#derived-signals
We're talking about derived signals which are just functions accessing other signals/memos in their body