Skip to content

Allow createStructuredSelector to derive the types #476

@arendjr

Description

@arendjr

When using createStructuredSelector() I discovered it's rather tedious to have to manually provide types for the generics. The function is supposed to help reduce boilerplate, but if you need to provide the types manually, it doesn't help that much after all...

So I created my own type definition that derives the types automatically.

Right now I have a file called types/reselect/index.d.ts in my project that extends the typings from Reselect itself, like this:

namespace Reselect {
  export function createStructuredSelector<
    S,
    T extends Record<string, Reselect.Selector<S>>
  >(
    selectors: T,
    selectorCreator?: typeof Reselect.createSelector
  ): Reselect.Selector<S, { [K in keyof T]: ReturnType<T[K]> }>;
}

Would the maintainers be interested in upstreaming this? If so, I can help create a PR, or feel free to use this snippet as is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions