![](/img/trans.png)
[英]I'm working to complete redux with typescript. How can I adjust type what I want in these actions
[英]How can I avoid any type in redux Typescript
我想避免 react-redux typescript 项目中的“任何”类型。 我是 typescript 的新手,但我喜欢它,但我不明白应该在哪里使用任何类型。
在哪里使用它,在哪里不使用它?
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;
在您的情况下,您可以将state:any
更改为state:InitialState[]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.