// store.ts
import { configureStore } from "@reduxjs/toolkit"
import transformReducer from "./home/useTransform"
import showPointReducer from "./home/useShowPoint"
import measureReducer from "./home/useMeasure"
import pointReducer from "./home/useDataPoints"
import tableDataReducer from "./home/getTableData"
// store 报错
// TS4023: Exported variable store has or is using name CounterState from external module
// "E:/Codes/works/iocs-web-ceph/src/stores/home/getTableData"
// but cannot be named.
// CounterState 是下面 getTableData.ts 的 Slice 的类型
const store = configureStore({
reducer: {
transform: transformReducer,
showPoint: showPointReducer,
measure: measureReducer,
dataPoint: pointReducer,
tableData: tableDataReducer,
},
})
export default store
export type RootState = ReturnType<typeof store.getState>
// ./home/getTableData.ts
import { createSlice } from "@reduxjs/toolkit"
import type { Slice } from "@reduxjs/toolkit"
import type { ITableData } from "@/apis/getList"
interface CounterState {
rulerScaling: number
tableData: ITableData[]
}
export const counterSlice: Slice<CounterState> = createSlice({
name: "tableData",
initialState: {
rulerScaling: 1,
tableData: [] as ITableData[]
},
reducers: {
setTableData(state, action) {
state.tableData = action.payload
},
setRulerScaling(state, action) {
state.rulerScaling = action.payload
}
}
})
export const { setTableData, setRulerScaling } = counterSlice.actions
export default counterSlice.reducer
因为 getTableData 这个文件定义了counterSlice 的类型, 其他都没有定义,因为别的地方只有getTableData需要用到类型
但是store 里报错
TS4023: Exported variable store has or is using name CounterState from external module
"E:/Codes/works/iocs-web-ceph/src/stores/home/getTableData"
but cannot be named.
这个怎么解决?