Skip to content

Commit

Permalink
Omit injected props from WithSizes return type
Browse files Browse the repository at this point in the history
The output component after the HOC has been applied should not support
the same props that are injected by it. Even if it did support them,
they would be overwritten by the HOC.

More details on this can be found in the original draft for these types:
renatorib/react-sizes#13 (comment)
  • Loading branch information
pinn3 authored and jorrit committed Jan 13, 2025
1 parent dde4bd1 commit 4a97568
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion types/react-sizes/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export interface Sizes {

export function WithSizes<SP extends object, P extends SP>(
mapSizesToProps: (sizes: Sizes) => SP,
): (component: React.ComponentType<P>) => React.ComponentType<P>;
): (component: React.ComponentType<P>) => React.ComponentType<Omit<P, keyof SP>>;

export default WithSizes;
5 changes: 2 additions & 3 deletions types/react-sizes/react-sizes-tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ interface TestProps {
height: number;
}

const mapSizesToProps = ({ width, height }: Sizes): TestProps => ({
foo: "foo",
const mapSizesToProps = ({ width, height }: Sizes) => ({
width,
height,
});
Expand All @@ -26,4 +25,4 @@ const TestComponent: React.ComponentType<TestProps> = ({ foo, width, height }) =
);
};

WithSizes(mapSizesToProps)(TestComponent); // $ExpectType ComponentType<TestProps>
WithSizes<ReturnType<typeof mapSizesToProps>, TestProps>(mapSizesToProps)(TestComponent); // $ExpectType ComponentType<Omit<TestProps, "width" | "height">>

0 comments on commit 4a97568

Please sign in to comment.