deepComputed
returns a signal instead of a deepSignal when used in withComputed
#4775
-
I have a simple user store like the following
and my
However this is returning a plain signal not a deep signal. Inside the component if I set the |
Beta Was this translation helpful? Give feedback.
Answered by
rainerhahnekamp
May 7, 2025
Replies: 1 comment 4 replies
-
I just tried it out, but on my machine interface IUser {
id: number;
name: string;
}
interface State {
all: Record<string, IUser>;
selectedId: string;
}
const A = signalStore(
withState<State>({ all: {}, selectedId: '' }),
withComputed(({ selectedId, all }) => ({
selectedUser: deepComputed(() => all()[selectedId()]),
})),
);
const a = new A();
a.selectedUser.name(); |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem is that you are accessing an entry of a Record which doesn't exist. TypeScript doesn't give you an undefined either and that's why you don't get a compilation error. But during runtime - when deepComputed - hits the
undefined
you are getting the error.In your case, I would set a default value for selected or return a default user in
deepComputed
if it is undefined,.