Skip to content

Commit

Permalink
fix: add typings so withDeprecatedProps() returns the original props
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed May 17, 2024
1 parent 89218ea commit 5096728
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/withDeprecatedProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ export interface DeprecatedProps extends Record<string, any> {
message?: string,
}

function withDeprecatedProps<T extends Record<string, any>>(
WrappedComponent: React.ComponentType<any>,
function withDeprecatedProps<
Props,
C extends React.ComponentType<Props>,
DeprProps extends Record<string, DeprecatedProps>,
>(
WrappedComponent: C,
componentName: string,
deprecatedProps: Record<string, DeprecatedProps>,
) : any {
class WithDeprecatedProps extends React.Component<T> {
deprecatedProps: DeprProps,
) : C {
class WithDeprecatedProps extends React.Component<Props & Record<keyof DeprProps, unknown>> {
// eslint-disable-next-line react/static-property-placement
public static displayName = `withDeprecatedProps(${componentName})`;

constructor(props: T) {
constructor(props: Props & Record<keyof DeprProps, unknown>) {
super(props);
this.transformProps = this.transformProps.bind(this);
}
Expand Down Expand Up @@ -84,14 +88,14 @@ function withDeprecatedProps<T extends Record<string, any>>(
.reduce(this.transformProps, {});

return (
<WrappedComponent {...transformedProps as T}>
<WrappedComponent {...transformedProps as any}>
{this.props.children || children}
</WrappedComponent>
);
}
}

return WithDeprecatedProps;
return WithDeprecatedProps as any as C;
}

export default withDeprecatedProps;

0 comments on commit 5096728

Please sign in to comment.