Skip to content

Commit ab011e7

Browse files
committed
chore: adopt isolatedDeclarations and upgrade to TypeScript 7.0.2
1 parent 8fd40f6 commit ab011e7

25 files changed

Lines changed: 374 additions & 40 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
"rolldown": "^1.2.3",
120120
"tsdown": "^0.23.0-beta.2",
121121
"tsx": "^4.23.10",
122-
"typescript": "^6.0.3",
122+
"typescript": "^7.0.2",
123123
"unrun": "^0.3.1",
124124
"vitest": "^4.1.10"
125125
},

src/components/Context.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ function getContext(): Context<ReactReduxContextValue | null> {
4545
return realContext
4646
}
4747

48-
export const ReactReduxContext = /*#__PURE__*/ getContext()
48+
export const ReactReduxContext: Context<ReactReduxContextValue<
49+
any,
50+
UnknownAction
51+
> | null> = /*#__PURE__*/ getContext()
4952

5053
export type ReactReduxContextInstance = typeof ReactReduxContext

src/components/Provider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export interface ProviderProps<
5656

5757
export function Provider<A extends Action<string> = UnknownAction, S = unknown>(
5858
providerProps: ProviderProps<A, S>,
59-
) {
59+
): React.JSX.Element {
6060
if (process.env.NODE_ENV !== 'production') {
6161
// React Server Components do not provide the effect hooks that `<Provider>`
6262
// relies on, so `useIsomorphicLayoutEffect` (which resolves to

src/connect/invalidArgFactory.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import type { Action, Dispatch } from 'redux'
22

3-
export function createInvalidArgFactory(arg: unknown, name: string) {
3+
export function createInvalidArgFactory(
4+
arg: unknown,
5+
name: string,
6+
): (
7+
dispatch: Dispatch<Action<string>>,
8+
options: { readonly wrappedComponentName: string },
9+
) => never {
410
return (
511
dispatch: Dispatch<Action<string>>,
612
options: { readonly wrappedComponentName: string },

src/connect/mapDispatchToProps.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import type { Action, Dispatch } from 'redux'
22
import { bindActionCreators } from '../utils/bindActionCreators'
33
import { createInvalidArgFactory } from './invalidArgFactory'
44
import type { MapDispatchToPropsParam } from './selectorFactory'
5+
import type { InitProxyOptions, WrappedMapToProps } from './wrapMapToProps'
56
import { wrapMapToPropsConstant, wrapMapToPropsFunc } from './wrapMapToProps'
67

78
export function mapDispatchToPropsFactory<TDispatchProps, TOwnProps>(
89
mapDispatchToProps:
910
| MapDispatchToPropsParam<TDispatchProps, TOwnProps>
1011
| undefined,
11-
) {
12+
): (
13+
dispatch: Dispatch<Action<string>>,
14+
options: InitProxyOptions,
15+
) => WrappedMapToProps {
1216
return mapDispatchToProps && typeof mapDispatchToProps === 'object'
1317
? wrapMapToPropsConstant((dispatch: Dispatch<Action<string>>) =>
1418
// @ts-ignore

src/connect/mapStateToProps.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import type { Action, Dispatch } from 'redux'
12
import { createInvalidArgFactory } from './invalidArgFactory'
23
import type { MapStateToPropsParam } from './selectorFactory'
4+
import type { InitProxyOptions, WrappedMapToProps } from './wrapMapToProps'
35
import { wrapMapToPropsConstant, wrapMapToPropsFunc } from './wrapMapToProps'
46

57
export function mapStateToPropsFactory<TStateProps, TOwnProps, State>(
68
mapStateToProps: MapStateToPropsParam<TStateProps, TOwnProps, State>,
7-
) {
9+
): (
10+
dispatch: Dispatch<Action<string>>,
11+
options: InitProxyOptions,
12+
) => WrappedMapToProps {
813
return !mapStateToProps
914
? wrapMapToPropsConstant(() => ({}))
1015
: typeof mapStateToProps === 'function'

src/connect/mergeProps.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,14 @@ export function mergePropsFactory<
6969
TMergedProps,
7070
>(
7171
mergeProps?: MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps>,
72-
) {
72+
): (
73+
dispatch: Dispatch<Action<string>>,
74+
options: {
75+
readonly displayName: string
76+
readonly wrappedComponentName: string
77+
readonly areMergedPropsEqual: EqualityFn<TMergedProps>
78+
},
79+
) => MergeProps<TStateProps, TDispatchProps, TOwnProps, TMergedProps> {
7380
return !mergeProps
7481
? () => defaultMergeProps
7582
: typeof mergeProps === 'function'

src/connect/selectorFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export function finalPropsSelectorFactory<
227227
TMergedProps,
228228
State
229229
>,
230-
) {
230+
): (nextState: State, nextOwnProps: TOwnProps) => TMergedProps {
231231
const mapStateToProps = initMapStateToProps(dispatch, options)
232232
const mapDispatchToProps = initMapDispatchToProps(dispatch, options)
233233
const mergeProps = initMergeProps(dispatch, options)

src/connect/wrapMapToProps.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@ export type MapToProps<P extends AnyProps = AnyProps> = {
1313
dependsOnOwnProps?: boolean
1414
}
1515

16+
/**
17+
* What the `init*` factories below hand back to `selectorFactory`: the same
18+
* call signature as {@linkcode MapToProps}, but with `dependsOnOwnProps`
19+
* always present — `selectorFactory` reads it unconditionally.
20+
*/
21+
export type WrappedMapToProps<P extends AnyProps = AnyProps> = {
22+
(stateOrDispatch: StateOrDispatch, ownProps?: P): FixTypeLater
23+
dependsOnOwnProps: boolean
24+
}
25+
26+
/**
27+
* The fields of `selectorFactory`'s `InitOptions` that the `init*` factories
28+
* actually read. Kept structural (rather than importing `InitOptions`) so the
29+
* two modules don't have to agree on its type parameters.
30+
*/
31+
export type InitProxyOptions = {
32+
readonly displayName: string
33+
readonly wrappedComponentName: string
34+
}
35+
1636
export function wrapMapToPropsConstant(
1737
// * Note:
1838
// It seems that the dispatch argument
@@ -26,7 +46,7 @@ export function wrapMapToPropsConstant(
2646
}
2747
| ActionCreatorsMapObject
2848
| ActionCreator<any>,
29-
) {
49+
): (dispatch: Dispatch) => WrappedMapToProps {
3050
return function initConstantSelector(dispatch: Dispatch) {
3151
const constant = getConstant(dispatch)
3252

@@ -67,7 +87,10 @@ function getDependsOnOwnProps(mapToProps: MapToProps) {
6787
export function wrapMapToPropsFunc<P extends AnyProps = AnyProps>(
6888
mapToProps: MapToProps,
6989
methodName: string,
70-
) {
90+
): (
91+
dispatch: Dispatch,
92+
factoryOptions: { displayName: string },
93+
) => WrappedMapToProps<P> {
7194
return function initProxySelector(
7295
dispatch: Dispatch,
7396
{ displayName }: { displayName: string },

src/hooks/useDispatch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,5 @@ export function createDispatchHook<
100100
* )
101101
* }
102102
*/
103-
export const useDispatch = /*#__PURE__*/ createDispatchHook()
103+
export const useDispatch: UseDispatch<Dispatch<UnknownAction>> =
104+
/*#__PURE__*/ createDispatchHook()

0 commit comments

Comments
 (0)