Skip to content

Signal store - How to get the types right for a custom store feature that uses factory-method? #4566

Discussion options

You must be logged in to vote

After extensive discussions about the depths of Typescript and the approaches you can use in various scenarios within the Angular discord , the consensus was pretty much: I must use type-casting to establish which properties get added to the store, as TS can not properly infer those for me. The key problem for that inference is Object.keys(queries) as that turns all the property names into the type "string[]" instead of a type-union of property-names.

Since that is the case, I kind of just started brute-forcing the issue, which worked a lot easier than anticipated:

/withQueries/index.ts
import { WritableStateSource } from '@ngrx/signals';
import {
  MethodsDictionary,
  SignalStoreFeature

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@PhilippMDoerner
Comment options

@PhilippMDoerner
Comment options

Comment options

You must be logged in to vote
1 reply
@PhilippMDoerner
Comment options

Answer selected by PhilippMDoerner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants