尝试用类型记录和redux设置一个项目。我收到了这个错误
Generic type 'Dispatch<S>' requires 1 type argument(s).这是我的store.ts
import { connectRouter, routerMiddleware } from 'connected-react-router'
import { applyMiddleware, compose, createStore } from 'redux'
import { createLogger } from 'redux-logger'
import ReduxThunk from 'redux-thunk'
import { createBrowserHistory } from 'history'
import reducers from './reducers'
import { composeWithDevTools } from 'redux-devtools-extension'
export const history = createBrowserHistory()
const composeEnhancers = composeWithDevTools({
// Specify name here, actionsBlacklist, actionsCreators and other options if needed
})
const logger = createLogger()
const middleware = [ReduxThunk, logger]
const Store = createStore(connectRouter(history)(reducers), {}, composeEnhancers(applyMiddleware(...middleware, routerMiddleware(history))))
export default Store这是根减速器
import { combineReducers } from 'redux'
import { ActionType } from 'typesafe-actions'
import * as actions from '../actions'
export interface IState {
test: string
}
export type Actions = ActionType<typeof actions>
export default combineReducers<IState, Actions>({
test: () => 'hey'
})下面是一些愚蠢的行为
import { action } from 'typesafe-actions'
export const toggle = (id: string) => action('TOGGLE', id)
// (id: string) => { type: 'todos/TOGGLE'; payload: string; }最后是index.ts
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import App from './App'
import './index.scss'
import registerServiceWorker from './registerServiceWorker'
import store, { history } from './store'
import { Provider } from 'react-redux'
import { Route, Switch } from 'react-router' // react-router v4
import { ConnectedRouter } from 'connected-react-router'
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}> { /* place ConnectedRouter under Provider */}
<div> { /* your usual react-router v4 routing */}
<Switch>
<Route exact path="/" render={() => (<div>Match</div>)} />
<Route render={() => (<div>Miss</div>)} />
</Switch>
</div>
</ConnectedRouter>
</Provider>,
document.getElementById('root') as HTMLElement
)
registerServiceWorker()在没有解决方案的情况下,https://github.com/DefinitelyTyped/DefinitelyTyped/issues/9611似乎也有类似的问题
但我对打字很陌生,所以可能缺少一些基本的东西。
发布于 2018-08-02 17:36:31
在我看来,你确实面临着同样的问题。当我们等待并查看7mllm7的拉请求是否合并时,您可以使用他修改后的react类型。我建议采取以下方法:
git clone --depth=1 https://github.com/7mllm7/DefinitelyTypedtypes/react-redux文件夹复制到项目中(例如,将其复制到名为react-redux.fixed的文件夹中)。react-redux.fixed/package.json以将"private": "true"替换为"name": "@types/react-redux"。package.json中,将@types/react-redux的版本指定为./react-redux.fixed。npm install。npm将建立一个从node_modules/@types/react-redux到react-redux.fixed的符号链接。与仅在node_modules/@types/react-redux中编辑文件相比,npm知道您使用的是修改后的包版本,不会覆盖它。(这个过程应该广为人知;如果我有时间,我会找到一个更好的地方来记录它。)
https://stackoverflow.com/questions/51655546
复制相似问题