Is there a way to get the types of module
pkrinesh opened this issue · 2 comments
pkrinesh commented
Can we get the types of module so we can use in other part of application?
InfiniteXyy commented
I would create a type outside the module, if I want to reuse the type
type CounterState = { count: number; input: string };
const CounterModule = defineModule<CounterState>({ count: 0, input: "hello" }).build();
If you want to infer from the module type, you can use this InferModuleType
utility
type InferModuleState<T> = T extends { getState(): infer U } ? U : never;
const CounterModule = defineModule({ count: 0, input: "hello" }).build();
type CounterState = InferModuleState<typeof CounterModule>;
pkrinesh commented
Sure, we can use the utility type function.
Thanks