Correct typing with withCallState within custom feature #4710
Answered
by
rainerhahnekamp
jan-willem-baart
asked this question in
Q&A
-
Trying to use withCallState within withAutocomplete but can't manage to get the typing correct of the returned signalstore, see example. Any tips on how to get this working?
|
Beta Was this translation helpful? Give feedback.
Answered by
rainerhahnekamp
Mar 8, 2025
Replies: 1 comment
-
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 })
) as AutocompleteSignalStoreFeature<Collection>;
} |
Beta Was this translation helpful? Give feedback.
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
@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.