Has anyone been able to specify the return type of the createSelector
function in Redux's Reselect library?
I didn't find any information on this in the official documentation: https://github.com/reduxjs/reselect#q-are-there-typescript-typings
This cheatsheet also doesn't seem to cover this topic: https://github.com/piotrwitek/react-redux-typescript-guide#selectors-with-reselect
import { createSelector } from 'reselect';
import { TodosState } from './reducer';
export const getTodos = (state: TodosState) => state.todos;
export const getTodosFilter = (state: TodosState) => state.todosFilter;
export const getFilteredTodos = createSelector(getTodos, getTodosFilter, (todos, todosFilter) => {
switch (todosFilter) {
case 'completed':
return todos.filter(t => t.completed);
case 'active':
return todos.filter(t => !t.completed);
default:
return todos;
}
});
If I have an idea about the return type of getFilteredTodos
like this:
type Return = {
text: string;
completed: boolean;
}[]
Do you think it is possible to define this?