Skip to content

Correct typing with withCallState within custom feature #4710

Discussion options

You must be logged in to vote

@jan-willem-baart

I don’t see an issue with giving TypeScript a little nudge in the right direction using type assertions. Your use case isn’t trivial, and even advanced features like withCallState rely on type assertions.

export function withAutocomplete<Collection extends string>(config: {
  collection: Collection;
}): AutocompleteSignalStoreFeature<Collection> {
  const { optionsKey, selectedOptionKey, selectedOptionIdKey, queryKey } =
    getNamedAutocompleteKeys(config);

  return signalStoreFeature(
    withState({
      [optionsKey]: [],
      [selectedOptionKey]: null,
      [selectedOptionIdKey]: '',
      [queryKey]: '',
    }),
    withCallState({ collection: config.collection })

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jan-willem-baart
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