Skip to content

Getting error with TypeScript... #51

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

Closed
born2net opened this issue Jan 25, 2016 · 11 comments
Closed

Getting error with TypeScript... #51

born2net opened this issue Jan 25, 2016 · 11 comments

Comments

@born2net
Copy link

Hello,
I am getting:

capture

when applying:
import thunkMiddleware from "redux-thunk"
let createStoreWithMiddleware = applyMiddleware(thunkMiddleware)(createStore);

any known issues?

regards

Sean

@born2net
Copy link
Author

will get you a free Enterprise account at http://www.digitalsignage.com if you want as tx... :)
and remember to use the Redux branch

@gaearon
Copy link
Collaborator

gaearon commented Jan 25, 2016

It is definitely not a problem with this library.
There is not enough information to say what the issue is as you have not provided the source code.
Please feel free to take this to StackOverflow as it's a better place to ask usage questions.

@gaearon gaearon closed this as completed Jan 25, 2016
@alexanderharm
Copy link

Import it like this:
import {compose, createStore, applyMiddleware} from 'redux'
// important: use require for redux-thunk
import thunk = require('redux-thunk')
// setup like this
let createStoreWithMiddleware = compose(applyMiddleware(thunk))(createStore)
let store = createStoreWithMiddleware(rootReducer)
I use it like this with Angular2. Also map 'redux-thunk' to your .js file in your SystemJS config.

@gaearon
Copy link
Collaborator

gaearon commented Feb 2, 2016

Interesting. Apparently TypeScript doesn't provide interop with CommonJS modules.
We will release Redux Thunk 2.0 later that will have a proper default export so that will be solved.

In the meantime, rather than

let createStoreWithMiddleware = compose(applyMiddleware(thunk))(createStore)
let store = createStoreWithMiddleware(rootReducer)

you can write

let store = createStore(
  rootReducer,
  applyMiddleware(thunk)
)

if you use Redux >= 3.1.0.

@alexanderharm
Copy link

OK thanks. I will look forward to the new release. Also SystemJS does not handle the process.env.NODE_ENV correctly if not bundled. A basic redux implementation in Angular2 can be found here: https://github.com/jhades/angular2-redux-store (helped me a lot).

@franleplant
Copy link

Sorry to step in but after 1 hour of trying to make Typescript and Redux work together your solution was the only one working @gaearon :

let store = createStore(
  rootReducer,
  applyMiddleware(thunk)
)

I don't know if anyone else will find this useful or if this is the right place but that's all I got.

The error was this:

error TS2345: Argument of type '(...args: any[]) => (reducer: <A extends Action>(state: {}, action: A) => {}, preloadedState?: {}...' is not assignable to parameter of type '(next: (reducer: <A extends Action>(state: AppState, action: A) => AppState, preloadedState?: App...'.
  Type '(reducer: <A extends Action>(state: {}, action: A) => {}, preloadedState?: {}) => Store<{}>' is not assignable to type '(reducer: <A extends Action>(state: AppState, action: A) => AppState, preloadedState?: AppState) ...'.
    Type 'Store<{}>' is not assignable to type 'Store<AppState>'.
      Type '{}' is not assignable to type 'AppState'.

When using compose. It might be that compose type definition is broken in @types/redux v3.6.31

@aikoven
Copy link
Collaborator

aikoven commented Nov 9, 2016

@franleplant Maybe this will help: reduxjs/redux#1937

@franleplant
Copy link

franleplant commented Nov 9, 2016

Thanks a lot! I've tried that after reading through the Type definition
files (yeah, Im crazy like that) but it did not work. In any case not using
compose at all did the job.
Thanks @aikoven !

On Wed, Nov 9, 2016 at 5:11 AM Daniel Lytkin [email protected]
wrote:

@franleplant https://github.com/franleplant Maybe this will help:
reduxjs/redux#1937 reduxjs/redux#1937


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#51 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABxEJ1e2fWT6aEwRmQgxLLL28btADEJDks5q8YAfgaJpZM4HL0-Z
.

@empz
Copy link

empz commented Nov 23, 2016

@franleplant I'm having the same problem using redux 3.6.0. Your solution works but how to add the devToolsExtension?

@franleplant
Copy link

If you have the time, the best thing to do is to report this to
Definitelytyped repo (good luck finding yourself around). Have you tried
the alternatives discussed in all these related issues?

On Wed, Nov 23, 2016 at 6:58 PM emzero [email protected] wrote:

@franleplant https://github.com/franleplant I'm having the same problem
using redux 3.6.0. Your solution works but how to add the devToolsExtension?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#51 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABxEJ9U3nSJRI9tc9Jx7bg-d74ojRRbYks5rBLcHgaJpZM4HL0-Z
.

@empz
Copy link

empz commented Nov 23, 2016

I've found a way. Leaving it here in case anybody else needs it.

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(rootReducer, {}, composeEnhancers(
  applyMiddleware(thunk)
));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants