Skip to content

Commit

Permalink
Use a Mapped type to simplify the final displayed types for components
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Sep 23, 2022
1 parent 16c829b commit b9ec3a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ export type ConnectPropsMaybeWithoutContext<TActualOwnProps> =
? Omit<ConnectProps, 'context'>
: ConnectProps

type Identity<T> = T
export type Mapped<T> = Identity<{ [k in keyof T]: T[k] }>

// Injects props and removes them from the prop requirements.
// Will not pass through the injected props if they are passed in during
// render. Also adds new prop requirements from TNeedsProps.
Expand All @@ -109,8 +112,9 @@ export type InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> = <
GetLibraryManagedProps<C>,
keyof Shared<TInjectedProps, GetLibraryManagedProps<C>>
> &
TNeedsProps &
ConnectPropsMaybeWithoutContext<TNeedsProps & GetProps<C>>
Mapped<
TNeedsProps & ConnectPropsMaybeWithoutContext<TNeedsProps & GetProps<C>>
>
>

// Injects props and removes them from the prop requirements.
Expand Down
2 changes: 1 addition & 1 deletion test/typetests/connect-options-and-issues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ function TestOptionalPropsMergedCorrectly() {
}
}

connect(mapStateToProps, mapDispatchToProps)(Component)
const Connected = connect(mapStateToProps, mapDispatchToProps)(Component)
}

function TestMoreGeneralDecorationProps() {
Expand Down

0 comments on commit b9ec3a7

Please sign in to comment.