Skip to content

How to get the right type for a callback that acts on a signal store's custom-feature data? #4543

Discussion options

You must be logged in to vote

@PhilippMDoerner, you do it the other way around. You define the callback as private method, and the extension uses it then:

https://stackblitz.com/edit/github-kvtghf-9o34rq?file=src%2FwithExample.ts

export const ExampleStore = signalStore(
  { providedIn: 'root' },
  withMethods((store) => ({
    _exampleCb() {
      // code for callback here...
    },
  })),
  withExample('example'),
  withExample('other')
);

export function withExample<Prop extends string>(
  name: Prop
): SignalStoreFeature<EmptyFeature, FilledFeature<Prop>> {
  return signalStoreFeature(
    { methods: type<{ _exampleCb: () => void }>() },
    withState<ExampleState<Prop>>({
      [`${name}Field`]: 'foo',
    } as E…

Replies: 1 comment 8 replies

Comment options

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

@rainerhahnekamp
Comment options

Answer selected by PhilippMDoerner
@PhilippMDoerner
Comment options

@rainerhahnekamp
Comment options

@PhilippMDoerner
Comment options

@rainerhahnekamp
Comment options

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