简化示例
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
type Cake = {
flavor: string;
size: 'S' | 'M' | 'L';
};
const initialState: { all: Cake[]; meta: { currentPage: number } } = {
all: [],
meta: {
currentPage: 0,
},
};
const cakeSlice = createSlice({
name: 'cake',
initialState,
reducers: {
fetchAll(
state,
action: PayloadAction<Cake[], string, { currentPage: number }>,
) {
state.all = action.payload;
state.meta = action.meta;
},
},
});
export default cakeSlice;
我收到这些错误。
Type '
(state: {
all: {
flavor: string;size: "S" | "M" | "L";
} [];meta: {
currentPage: number;
};
}, action: PayloadAction < Cake[], string, {
currentPage: number;
}, never > ) => void ' is not assignable to type '
CaseReducer < {
all: Cake[];meta: {
currentPage: number;
};
}, {
payload: any;type: string;
} > | CaseReducerWithPrepare < {
all: Cake[];meta: {
currentPage: number;
};
}, {
payload: any;type: string;
} > '
Type '
(state: {
all: {
flavor: string;size: "S" | "M" | "L";
} [];meta: {
currentPage: number;
};
}, action: PayloadAction < Cake[], string, {
currentPage: number;
}, never > ) => void '
is not assignable to type 'CaseReducer<{ all: Cake[]; meta: { currentPage: number; }; }, { payload: any; type: string; }>'.
Types of parameters 'action'
and 'action'
are incompatible.
Type '{ payload: any; type: string; }'
is not assignable to type 'PayloadAction<Cake[], string, { currentPage: number; }, never>'.
Property 'meta'
is missing in type '{ payload: any; type: string; }'
but required in type '{ meta: { currentPage: number; }; }
'.