#Mutating signal from toSignal()

8 messages · Page 1 of 1 (latest)

rose tulip
#

Hey, I have 2 questions regarding the new signals. I'm trying to simulate a slow call to an API which returns an observable.
Is it possible to get a WritableSignal<T> from the toSignal() function, instead of a signal<T>?
I want to fetch a user object and then mutate said object.

Also, on line 27, should typescript not infer that this.user() is not undefined with the type guard on line 23?

I know in this example I can pass inn an initial value to user but in reality this probably would not be feasible.

surreal nymph
#

toSignal returns Signal<T|undefined>

#

because signals have a default value

#

until the observable sends a value, signal is undefined

#

also that signal isn't supposed to be writable because it is "populated" by the observable

lime pewter
cyan forum
rose tulip