Skip to content

How to Pass Generics to createSelector With Arguments? #742

Open
@elsonel

Description

@elsonel
export const selectFormValues = createSelector<
  [
    (state: RootState) => RootState['sliceValues'],
    (state: RootState, type: T) => T
  ],
  TypeToFormMap[T]
>(
  [
    (state) => state.sliceValues,
    (state, type) => type,
  ],
  (sliceValues, type) => sliceValues.formValuesMap[type]
);

Where could I define the generic T for something like this?

// Usage:

// TypeToFormMap['goal-form']
const values = useSelector((state: RootState) => selectFormValues(state, 'goal-form')

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions