Skip to content

How could I get the type of the state derived from a signalStoreFeature? #4765

Answered by Pizzicato
Pizzicato asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, thanks!
I didn't think of writing a explicit type, but it would be quite monstrous and hard to maintain as the withCrud feature includes quite a bit of methods and properties. I have created these type utils to make the conversion and they seem to be working but I'm not sure how hacky they are, what do you think?

type Signalify<T> = { [K in keyof T]: Signal<T[K]> };
type ToState<T extends SignalStoreFeatureResult> = Signalify<T['state']> & T['props'] & T['methods'];

type CrudFeatureProps = ReturnType<typeof withCrud> extends SignalStoreFeature<any, infer O> ? O : never;
export type CrudStoreT = ToState<CrudFeatureProps>;

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@Pizzicato
Comment options

@rainerhahnekamp
Comment options

@Pizzicato
Comment options

Answer selected by Pizzicato
@rainerhahnekamp
Comment options

@Pizzicato
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