Skip to content

Commit ded7965

Browse files
committed
Omit injected props from WithSizes return type
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)
1 parent fb89400 commit ded7965

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

types/react-sizes/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface Sizes {
1010
}
1111

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

1616
export default WithSizes;

types/react-sizes/react-sizes-tests.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ interface TestProps {
77
height: number;
88
}
99

10-
const mapSizesToProps = ({ width, height }: Sizes): TestProps => ({
11-
foo: 'foo',
10+
const mapSizesToProps = ({ width, height }: Sizes) => ({
1211
width,
1312
height,
1413
});
@@ -26,4 +25,4 @@ const TestComponent: React.ComponentType<TestProps> = ({ foo, width, height }) =
2625
);
2726
};
2827

29-
WithSizes(mapSizesToProps)(TestComponent); // $ExpectType ComponentType<TestProps>
28+
WithSizes<ReturnType<typeof mapSizesToProps>, TestProps>(mapSizesToProps)(TestComponent); // $ExpectType ComponentType<Pick<TestProps, "foo">>

0 commit comments

Comments
 (0)