What type a derived signal should be?

just () => boolean or Accessor<boolean>?
7 Replies
Jasi
Jasi2mo ago
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
mbork.pl
mbork.pl2mo ago
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 props
Jasi
Jasi2mo ago
It'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!
gsoutz
gsoutz2mo ago
no createSignal<T>() must be typed by Signal<T> as best practice, imo.
Jasi
Jasi2mo ago
we're talking about derived signals, which are just functions
gsoutz
gsoutz2mo ago
oh you mean memo , so createMemo must be typed with Accessor for extra clarity.
Jasi
Jasi2mo ago
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
Want results from more Discord servers?
Add your server