-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Hoc broken with [email protected] #111
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
Comments
@belgattitude thanks for report, there was a change with generic object spread, I need to investigate Related: |
Thanks a lot... I'm trying to figure out as well. If I find something I'll let you know. Can be useful too: microsoft/TypeScript#28748 |
@issuehuntfest has funded $20.00 to this issue. See it on IssueHunt |
Looks like the TypeScript team thinks this is a bug and is trying to fix it by next release: Unfortunately, might mean it's difficult to fix from this side of things (though who knows, maybe there's a workaround) |
Thanks for heads-up @jkillian! I'll be tracking that one. |
Another related issue: microsoft/TypeScript#28884 |
@IssueHunt has funded $30.00 to this issue.
|
I can't adjust types to use Redux const tx = ...;
export type Translator = typeof tx;
interface InjectedProps {
t: Translator;
}
export const withTranslator = <BaseProps extends InjectedProps>(
_BaseComponent: React.ComponentType<BaseProps>,
) => {
// fix for TypeScript issues: https://github.com/piotrwitek/react-redux-typescript-guide/issues/111
const BaseComponent = _BaseComponent as React.ComponentType<InjectedProps>;
type HocProps = Subtract<BaseProps, InjectedProps>;
type TStateProps = ReturnType<typeof mapStateToProps>;
class Hoc extends React.Component<HocProps> {
static displayName = `injectL10n(${BaseComponent.name})`;
static readonly WrappedComponent = BaseComponent;
render() {
const { ...restProps } = this.props;
return <BaseComponent t={tx} {...restProps} />;
}
}
const mapStateToProps = (state: RootState) => ({
language: state.l10n.language,
});
// type error:
return connect<TStateProps, {}, HocProps, RootState>(mapStateToProps)(Hoc);
}; Error:
Thanks. |
I'm having the same issue as zdila. My Hoc using redux connect was working perfectly before I updated my typescript and redux packages. The code hasn't changed at all but I'm receiving these errors across all my Hocs which were built in exactly the same way. I'm using: |
@zdila this issue is reproduced without connect, but potentially can be related. |
For issues with nested HOC using |
The issue is fixed using: {...(restProps as BaseProps)} Full example: import React from 'react';
import { Diff } from 'utility-types';
interface InjectedProps {
count: number;
onIncrement: () => void;
}
export const withState = <BaseProps extends InjectedProps>(
BaseComponent: React.ComponentType<BaseProps>
) => {
type HocProps = Diff<BaseProps, InjectedProps> & {
initialCount?: number;
};
type HocState = {
readonly count: number;
};
return class Hoc extends React.Component<HocProps, HocState> {
static displayName = `withState(${BaseComponent.name})`;
static readonly WrappedComponent = BaseComponent;
readonly state: HocState = {
count: Number(this.props.initialCount) || 0,
};
handleIncrement = () => {
this.setState({ count: this.state.count + 1 });
};
render() {
const { ...restProps } = this.props;
const { count } = this.state;
return (
<BaseComponent
count={count}
onIncrement={this.handleIncrement}
{...(restProps as BaseProps)} // <= HERE
/>
);
}
};
}; |
… recent TypeScript 3.7 and React & Redux type definitions. (#193) * Updated deps * Updated deps and refactored code to fix breaking changes * Fixed issue with HOC Fixed #111 * Added an example of nested HOC with connect. Fixed #5 * Updated readme Intro & TOC * Updated PR template * Added new section with Nested HOC - wrapping a component, injecting props and connecting to redux #5 * Updated dev deps
@piotrwitek has rewarded $35.00 to @piotrwitek. See it on IssueHunt
|
Got an issue with hoc and typescript 3.2.1, any idea of what's missing
Based on latest master:
https://github.com/piotrwitek/react-redux-typescript-guide/blob/master/playground/src/hoc/with-state.tsx
Tsc will fail with
Any ideas ?
IssueHunt Summary
Backers (Total: $50.00)
Submitted pull Requests
Tips
IssueHunt has been backed by the following sponsors. Become a sponsor
The text was updated successfully, but these errors were encountered: