-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Redux connect fails with unable to resolve signature of class decorator when called as an expression #9365
Comments
I am using the latest react-redux definition from definitely typed, (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/react-redux/react-redux-2.1.2.d.ts), and i am unable to get a repro for this issue. can you provide more context? |
I am using |
I think the error is coming from: declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void; If |
The react-redux-2.1.2.d.ts is not the one I'm getting, which I installed with:
Which is registered in typings.json as:
Where export function connect(): InferableComponentDecorator;
export function connect<TStateProps, TDispatchProps, TOwnProps>(
mapStateToProps: MapStateToProps<TStateProps, TOwnProps>,
mapDispatchToProps?: MapDispatchToPropsFunction<TDispatchProps, TOwnProps>|MapDispatchToPropsObject
): ComponentDecorator<TStateProps & TDispatchProps, TOwnProps>;
export function connect<TStateProps, TDispatchProps, TOwnProps>(
mapStateToProps: MapStateToProps<TStateProps, TOwnProps>,
mapDispatchToProps: MapDispatchToPropsFunction<TDispatchProps, TOwnProps>|MapDispatchToPropsObject,
mergeProps: MergeProps<TStateProps, TDispatchProps, TOwnProps>,
options?: Options
): ComponentDecorator<TStateProps & TDispatchProps, TOwnProps>; TypeScript Type definition management is a broken mess, hoping TS v2.0 resolves a lot of the issues with it. It's a constant battle trying to use popular libraries like React/Redux which are frequently broken. |
So there's 2 versions of react-redux: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/react-redux But react-redux.d.ts was updated 2 months ago and react-redux-2.1.2.d.ts was updated 4 months ago, so I'm assuming |
Info here as well: DefinitelyTyped/DefinitelyTyped#8787 |
Thanks for the link @CarsonF; I filed DefinitelyTyped/DefinitelyTyped#9951 to track this issue centrally. Perhaps this issue should be closed in favor of that one and #4881? |
Here is a simplified code showing the issue:
Both 1.8.10 and 2.0.0 fails to compile it with following error:
Configuration:
|
TypeScript Version:
1.8.9
Not sure if this a TypeScript or Redux TypeScript definition issue but the behavior is unexpected. I'd like to use Redux connect() as a decorator which works fine when a React Component only has a single
render()
method, e.g:But it fails as soon as I add another method to the class, e.g:
Which fails with:
I don't understand how adding a method to a class changes the structure of a class to cause this error?
After some trial and error I'm able to workaround this by creating a constructor function that removes the type declarations from connect's constructor function:
Which now lets me use the decorator as expected:
But I'd prefer to be able to use react-redux native
@connect()
if possible. Is there anyway to resolve this issue without using a wrapper method?The text was updated successfully, but these errors were encountered: