Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typescript support #1

Open
reuzel opened this issue Apr 19, 2019 · 1 comment
Open

Add typescript support #1

reuzel opened this issue Apr 19, 2019 · 1 comment

Comments

@reuzel
Copy link

reuzel commented Apr 19, 2019

Hi,

Nice and simple utility! I missed the typescript support though. Made a start that works for me, but it still requires support for nested modules. I thought it would be nice to share it with you and the community...

Regards,
Joost

declare module "combine-selectors-redux" {

    type Selector<S, AS extends any[], R> = (state:S, ...args: AS) => R;
    type AnySelector<S> = Selector<S, any[], any>;
    type Module<S> = { [key:string]: AnySelector<S> }
    type ModuleState<M> = M extends Module<infer S> ? S : never
    type CombinedModuleState<CM> = { [K in keyof CM]: ModuleState<CM[K]>};

    type MappedSelector<LS, S, F> = F extends Selector<LS, infer AS, infer R> ? Selector<S, AS, R> : never;
    type MappedModule<M,S> = { [K in keyof M]: MappedSelector<ModuleState<M>, S, M[K]> }
    type CombinedSelectors<CS> = { [K in keyof CS]: MappedModule<CS[K], CombinedModuleState<CS>>}

    export function combineSelectors<T>(module: T): CombinedSelectors<T>
}
@tapayne88
Copy link
Owner

Hi @reuzel! Glad you're finding it useful. I'm slowly picking up typescript so I'll try to finish off the definitions! It should be a nice challenge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants