New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript errors in react-redux typings file #9611
Comments
This fixed it for me:
http://www.mzan.com/article/37714658-typescript-errors-in-react-redux-typings-file.shtml |
I've got the same issue. BTW, I am using tsd not typeings. i tried install typings but not work. |
@raineorshine thanks for the workaround 👍 Is there any progress about this issue? |
ping |
+1 |
1 similar comment
+1 |
+1 Having similar issues also with react and react-form |
+1 |
+1 Getting this now with redux-thunk and react-redux. Fixed by moving away from typings all together and using the new @types/* |
With @types everything works as expected. This should probably be closed? |
+1 |
I have the same issue using This is my dev dependencies Errors: (195,16): Generic type 'Dispatch (202,16): Generic type 'Dispatch (270,16): Generic type 'Dispatch (326,12): Generic type 'Store |
+1 |
TL;DRIf you change (even manually, just for trial) in the file My checkMy dependencies (from "dependencies": {
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-redux": "^5.0.7",
"react-scripts-ts": "2.16.0",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts-ts start",
"build": "react-scripts-ts build",
"test": "react-scripts-ts test --env=jsdom",
"eject": "react-scripts-ts eject",
"lint": "./node_modules/.bin/tslint --project . -c tslint.json"
},
"devDependencies": {
"@types/jest": "^23.3.1",
"@types/node": "^10.5.4",
"@types/react": "^16.4.7",
"@types/react-dom": "^16.0.6",
"@types/react-redux": "^6.0.5",
"@types/redux-logger": "^3.0.6",
"typescript": "^2.9.2"
}, And the errors I received looked like this:
So I went to the file above, inside interface MapDispatchToPropsFunction<TDispatchProps, TOwnProps> {
(dispatch: Dispatch, ownProps: TOwnProps): TDispatchProps;
} Note that import {
Action,
ActionCreator,
AnyAction,
Dispatch,
Store
} from 'redux'; Checking in export interface Dispatch<A extends Action = AnyAction> {
<T extends A>(action: T): T;
} So it looks like we just need to update https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-redux/index.d.ts to provide generic types to Now two questions:
|
Created #27724, let's see what the world thinks... |
This is blocking for me, is there an ETA on the merge? |
FWIW For me it was because I was using More info can be found here. |
Cross posting this comment: |
I think the problem is that current overrides for I suggest that corresponding This way you would be able to define store creation like this: // ./store.ts
import {applyMiddleware, createStore} from 'redux';
import thunk, {ThunkMiddleware, ThunkAction} from 'redux-thunk';
import {AppAction} from './actions';
import reducer from './reducers';
export interface AppState {
foo: string;
}
export function createAppStore() {
return createStore(
reducer,
{},
applyMiddleware(thunk as ThunkMiddleware<AppState, AppAction>)
);
}
export type AppStore = ReturnType<typeof createAppStore>;
export type AppThunk = ThunkAction<void, AppState, void, AppAction>; // ./thunks.ts
import {AppThunk} from './store'
export function thunkAction(): AppThunk {
return (dispatch, getState) => {
// launch missiles
};
} And when connecting a component: // ./some-container.ts
import {AppStore} from './store';
import {thunkAction} from './thunks'
export const Connected = connect<
{foo: string},
{onClick(): void},
{},
AppStore
>(
state => ({foo: 'bar'}), // state is inferred correctly to AppState
dispatch => ({ // dispatch is inferred correctly to AppStore['dispatch']
onClick() {
dispatch(thunkAction());
}
})
)(SomeComponent); |
I cloned a react project in my Mac which was probably developed under Windows. I did My Does anyone know how to fix this?
Here is a part of that
|
Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the |
react-redux.d.ts
file in this repo and had problems.react-redux.d.ts
.The TypeScript compiler is reporting errors in the react-redux typings file, even though I have excluded the typings directory in tsconfig.
TypeScript version: 1.8.10
Here are the errors I'm getting
ERROR in /home/me/dev/proj/typings/main/ambient/react-redux/index.d.ts (64,16): error TS2314: Generic type 'Dispatch' requires 1 type argument(s).
ERROR in /home/me/dev/proj/typings/main/ambient/react-redux/index.d.ts (68,21): error TS2314: Generic type 'ActionCreator' requires 1 type argument(s).
ERROR in /home/me/dev/proj/typings/main/ambient/react-redux/index.d.ts (95,13): error TS2314: Generic type 'Store' requires 1 type argument(s).
typings.json:
tsconfig.json:
Why is it reporting errors from an excluded directory? How can I eliminate these errors?
Thank you in advance
The text was updated successfully, but these errors were encountered: