Skip to content

Commit b9ec3a7

Browse files
committed
Use a Mapped type to simplify the final displayed types for components
1 parent 16c829b commit b9ec3a7

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/types.ts

Lines changed: 6 additions & 2 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.
@@ -109,8 +112,9 @@ export type InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> = <
109112
GetLibraryManagedProps<C>,
110113
keyof Shared<TInjectedProps, GetLibraryManagedProps<C>>
111114
> &
112-
TNeedsProps &
113-
ConnectPropsMaybeWithoutContext<TNeedsProps & GetProps<C>>
115+
Mapped<
116+
TNeedsProps & ConnectPropsMaybeWithoutContext<TNeedsProps & GetProps<C>>
117+
>
114118
>
115119

116120
// 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)