InfiniteXyy/zoov

Is there a way to get the types of module

pkrinesh opened this issue · 2 comments

Can we get the types of module so we can use in other part of application?

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>;

Sure, we can use the utility type function.

Thanks