Skip to content

Commit a071674

Browse files
authored
Fix types for other exports from extension package (#1331)
* Fix types for other imports from extension package Missed in #1323 * Create pink-bags-grab.md
1 parent 9536998 commit a071674

File tree

5 files changed

+62
-24
lines changed

5 files changed

+62
-24
lines changed

.changeset/pink-bags-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@redux-devtools/extension': patch
3+
---
4+
5+
Fix types for other exports from `@redux-devtools/extension`.

packages/redux-devtools-extension/src/developmentOnly.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
import { compose, StoreEnhancer } from 'redux';
2-
import { Config, EnhancerOptions } from './index';
1+
import { compose } from 'redux';
2+
import type { StoreEnhancer } from 'redux';
3+
import type {
4+
Config,
5+
EnhancerOptions,
6+
InferComposedStoreExt,
7+
ReduxDevtoolsExtensionCompose,
8+
} from './index';
39

410
declare const process: {
511
env: {
@@ -9,15 +15,21 @@ declare const process: {
915

1016
function extensionComposeStub(
1117
config: Config
12-
): (...funcs: StoreEnhancer[]) => StoreEnhancer;
13-
function extensionComposeStub(...funcs: StoreEnhancer[]): StoreEnhancer;
14-
function extensionComposeStub(...funcs: [Config] | StoreEnhancer[]) {
18+
): <StoreEnhancers extends readonly StoreEnhancer<unknown>[]>(
19+
...funcs: StoreEnhancers
20+
) => StoreEnhancer<InferComposedStoreExt<StoreEnhancers>>;
21+
function extensionComposeStub<
22+
StoreEnhancers extends readonly StoreEnhancer<unknown>[]
23+
>(
24+
...funcs: StoreEnhancers
25+
): StoreEnhancer<InferComposedStoreExt<StoreEnhancers>>;
26+
function extensionComposeStub(...funcs: [Config] | StoreEnhancer<unknown>[]) {
1527
if (funcs.length === 0) return undefined;
1628
if (typeof funcs[0] === 'object') return compose;
17-
return compose(...(funcs as StoreEnhancer[]));
29+
return compose(...(funcs as StoreEnhancer<unknown>[]));
1830
}
1931

20-
export const composeWithDevTools =
32+
export const composeWithDevTools: ReduxDevtoolsExtensionCompose =
2133
process.env.NODE_ENV !== 'production' &&
2234
typeof window !== 'undefined' &&
2335
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__

packages/redux-devtools-extension/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import Immutable from 'immutable';
2-
import { Action, ActionCreator, compose, StoreEnhancer } from 'redux';
1+
import type Immutable from 'immutable';
2+
import { compose } from 'redux';
3+
import type { Action, ActionCreator, StoreEnhancer } from 'redux';
34

45
export interface EnhancerOptions {
56
/**

packages/redux-devtools-extension/src/logOnly.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import assign from './utils/assign';
2-
import {
2+
import { compose } from 'redux';
3+
import type {
34
Action,
4-
compose,
55
Dispatch,
66
PreloadedState,
77
Reducer,
88
StoreEnhancer,
99
} from 'redux';
10-
import { Config, EnhancerOptions } from './index';
10+
import type { Config, EnhancerOptions, InferComposedStoreExt } from './index';
1111

1212
function enhancer(options?: EnhancerOptions): StoreEnhancer {
1313
const config: Config = options || {};
@@ -40,20 +40,28 @@ function enhancer(options?: EnhancerOptions): StoreEnhancer {
4040
}
4141

4242
function composeWithEnhancer(config?: EnhancerOptions) {
43-
return function (...funcs: StoreEnhancer[]) {
43+
return function (...funcs: StoreEnhancer<unknown>[]) {
4444
return compose(compose(...funcs), enhancer(config));
4545
};
4646
}
4747

4848
export function composeWithDevTools(
4949
config: Config
50-
): (...funcs: StoreEnhancer[]) => StoreEnhancer;
51-
export function composeWithDevTools(...funcs: StoreEnhancer[]): StoreEnhancer;
52-
export function composeWithDevTools(...funcs: [Config] | StoreEnhancer[]) {
50+
): <StoreEnhancers extends readonly StoreEnhancer<unknown>[]>(
51+
...funcs: StoreEnhancers
52+
) => StoreEnhancer<InferComposedStoreExt<StoreEnhancers>>;
53+
export function composeWithDevTools<
54+
StoreEnhancers extends readonly StoreEnhancer<unknown>[]
55+
>(
56+
...funcs: StoreEnhancers
57+
): StoreEnhancer<InferComposedStoreExt<StoreEnhancers>>;
58+
export function composeWithDevTools(
59+
...funcs: [Config] | StoreEnhancer<unknown>[]
60+
) {
5361
if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) {
5462
if (funcs.length === 0) return enhancer();
5563
if (typeof funcs[0] === 'object') return composeWithEnhancer(funcs[0]);
56-
return composeWithEnhancer()(...(funcs as StoreEnhancer[]));
64+
return composeWithEnhancer()(...(funcs as StoreEnhancer<unknown>[]));
5765
}
5866

5967
if (funcs.length === 0) return undefined;

packages/redux-devtools-extension/src/logOnlyInProduction.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import { compose, StoreEnhancer } from 'redux';
1+
import { compose } from 'redux';
2+
import type { StoreEnhancer } from 'redux';
23
import * as logOnly from './logOnly';
3-
import { Config, EnhancerOptions } from './index';
4+
import type {
5+
Config,
6+
EnhancerOptions,
7+
InferComposedStoreExt,
8+
ReduxDevtoolsExtensionCompose,
9+
} from './index';
410

511
declare const process: {
612
env: {
@@ -10,15 +16,21 @@ declare const process: {
1016

1117
function extensionComposeStub(
1218
config: Config
13-
): (...funcs: StoreEnhancer[]) => StoreEnhancer;
14-
function extensionComposeStub(...funcs: StoreEnhancer[]): StoreEnhancer;
15-
function extensionComposeStub(...funcs: [Config] | StoreEnhancer[]) {
19+
): <StoreEnhancers extends readonly StoreEnhancer<unknown>[]>(
20+
...funcs: StoreEnhancers
21+
) => StoreEnhancer<InferComposedStoreExt<StoreEnhancers>>;
22+
function extensionComposeStub<
23+
StoreEnhancers extends readonly StoreEnhancer<unknown>[]
24+
>(
25+
...funcs: StoreEnhancers
26+
): StoreEnhancer<InferComposedStoreExt<StoreEnhancers>>;
27+
function extensionComposeStub(...funcs: [Config] | StoreEnhancer<unknown>[]) {
1628
if (funcs.length === 0) return undefined;
1729
if (typeof funcs[0] === 'object') return compose;
18-
return compose(...(funcs as StoreEnhancer[]));
30+
return compose(...(funcs as StoreEnhancer<unknown>[]));
1931
}
2032

21-
export const composeWithDevTools =
33+
export const composeWithDevTools: ReduxDevtoolsExtensionCompose =
2234
process.env.NODE_ENV === 'production'
2335
? logOnly.composeWithDevTools
2436
: typeof window !== 'undefined' &&

0 commit comments

Comments
 (0)