How can I avoid any type in redux Typescript

Viewed 41

I want to avoid "any" type in the react-redux typescript project. I am new to typescript but I love it but I don't understand where I should use any type.

Where to use it and where not to use it?

import { createSlice } from "@reduxjs/toolkit";

export interface InitialState {
    id: string,
    name: string
}

const initialState: InitialState[] = [
    {id: '0', name: 'Jony'},
    {id: '1', name: 'kete'}
];


const userSlice = createSlice({
    name: 'users',
    initialState,
    reducers:{}
})

//Here I don't want to use any type
export const selectAllUser = (state:any) => state.users;

export default userSlice.reducer;
1 Answers

In your case you could change your state:any to state:InitialState[]

Related