Skip to content

Add typescript support #1

Open
Open
@reuzel

Description

@reuzel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions