Skip to content

Commit 1236861

Browse files
committed
Use a Mapped type to simplify the final displayed types for components
1 parent f40d82d commit 1236861

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/types.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ export type ConnectPropsMaybeWithoutContext<TActualOwnProps> =
9393
? Omit<ConnectProps, 'context'>
9494
: ConnectProps
9595

96+
type Identity<T> = T
97+
export type Mapped<T> = Identity<{ [k in keyof T]: T[k] }>
98+
9699
// Injects props and removes them from the prop requirements.
97100
// Will not pass through the injected props if they are passed in during
98101
// render. Also adds new prop requirements from TNeedsProps.
@@ -105,12 +108,14 @@ export type InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> = <
105108
component: C
106109
) => ConnectedComponent<
107110
C,
108-
DistributiveOmit<
109-
GetLibraryManagedProps<C>,
110-
keyof Shared<TInjectedProps, GetLibraryManagedProps<C>>
111-
> &
112-
TNeedsProps &
113-
ConnectPropsMaybeWithoutContext<TNeedsProps & GetProps<C>>
111+
Mapped<
112+
DistributiveOmit<
113+
GetLibraryManagedProps<C>,
114+
keyof Shared<TInjectedProps, GetLibraryManagedProps<C>>
115+
> &
116+
TNeedsProps &
117+
ConnectPropsMaybeWithoutContext<TNeedsProps & GetProps<C>>
118+
>
114119
>
115120

116121
// Injects props and removes them from the prop requirements.

test/typetests/connect-options-and-issues.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ function TestOptionalPropsMergedCorrectly() {
465465
}
466466
}
467467

468-
connect(mapStateToProps, mapDispatchToProps)(Component)
468+
const Connected = connect(mapStateToProps, mapDispatchToProps)(Component)
469469
}
470470

471471
function TestMoreGeneralDecorationProps() {

0 commit comments

Comments
 (0)