diff --git a/packages/redux-devtools-extension/src/developmentOnly.ts b/packages/redux-devtools-extension/src/developmentOnly.ts index 97b4deb4..74654fc2 100644 --- a/packages/redux-devtools-extension/src/developmentOnly.ts +++ b/packages/redux-devtools-extension/src/developmentOnly.ts @@ -1,5 +1,11 @@ -import { compose, StoreEnhancer } from 'redux'; -import { Config, EnhancerOptions } from './index'; +import { compose } from 'redux'; +import type { StoreEnhancer } from 'redux'; +import type { + Config, + EnhancerOptions, + InferComposedStoreExt, + ReduxDevtoolsExtensionCompose, +} from './index'; declare const process: { env: { @@ -9,15 +15,21 @@ declare const process: { function extensionComposeStub( config: Config -): (...funcs: StoreEnhancer[]) => StoreEnhancer; -function extensionComposeStub(...funcs: StoreEnhancer[]): StoreEnhancer; -function extensionComposeStub(...funcs: [Config] | StoreEnhancer[]) { +): []>( + ...funcs: StoreEnhancers +) => StoreEnhancer>; +function extensionComposeStub< + StoreEnhancers extends readonly StoreEnhancer[] +>( + ...funcs: StoreEnhancers +): StoreEnhancer>; +function extensionComposeStub(...funcs: [Config] | StoreEnhancer[]) { if (funcs.length === 0) return undefined; if (typeof funcs[0] === 'object') return compose; - return compose(...(funcs as StoreEnhancer[])); + return compose(...(funcs as StoreEnhancer[])); } -export const composeWithDevTools = +export const composeWithDevTools: ReduxDevtoolsExtensionCompose = process.env.NODE_ENV !== 'production' && typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ diff --git a/packages/redux-devtools-extension/src/index.ts b/packages/redux-devtools-extension/src/index.ts index 2186f1ab..b90d64d8 100644 --- a/packages/redux-devtools-extension/src/index.ts +++ b/packages/redux-devtools-extension/src/index.ts @@ -1,5 +1,6 @@ -import Immutable from 'immutable'; -import { Action, ActionCreator, compose, StoreEnhancer } from 'redux'; +import type Immutable from 'immutable'; +import { compose } from 'redux'; +import type { Action, ActionCreator, StoreEnhancer } from 'redux'; export interface EnhancerOptions { /** diff --git a/packages/redux-devtools-extension/src/logOnly.ts b/packages/redux-devtools-extension/src/logOnly.ts index 9528bafb..ef3c9aa2 100644 --- a/packages/redux-devtools-extension/src/logOnly.ts +++ b/packages/redux-devtools-extension/src/logOnly.ts @@ -1,13 +1,13 @@ import assign from './utils/assign'; -import { +import { compose } from 'redux'; +import type { Action, - compose, Dispatch, PreloadedState, Reducer, StoreEnhancer, } from 'redux'; -import { Config, EnhancerOptions } from './index'; +import type { Config, EnhancerOptions, InferComposedStoreExt } from './index'; function enhancer(options?: EnhancerOptions): StoreEnhancer { const config: Config = options || {}; @@ -40,20 +40,28 @@ function enhancer(options?: EnhancerOptions): StoreEnhancer { } function composeWithEnhancer(config?: EnhancerOptions) { - return function (...funcs: StoreEnhancer[]) { + return function (...funcs: StoreEnhancer[]) { return compose(compose(...funcs), enhancer(config)); }; } export function composeWithDevTools( config: Config -): (...funcs: StoreEnhancer[]) => StoreEnhancer; -export function composeWithDevTools(...funcs: StoreEnhancer[]): StoreEnhancer; -export function composeWithDevTools(...funcs: [Config] | StoreEnhancer[]) { +): []>( + ...funcs: StoreEnhancers +) => StoreEnhancer>; +export function composeWithDevTools< + StoreEnhancers extends readonly StoreEnhancer[] +>( + ...funcs: StoreEnhancers +): StoreEnhancer>; +export function composeWithDevTools( + ...funcs: [Config] | StoreEnhancer[] +) { if (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) { if (funcs.length === 0) return enhancer(); if (typeof funcs[0] === 'object') return composeWithEnhancer(funcs[0]); - return composeWithEnhancer()(...(funcs as StoreEnhancer[])); + return composeWithEnhancer()(...(funcs as StoreEnhancer[])); } if (funcs.length === 0) return undefined; diff --git a/packages/redux-devtools-extension/src/logOnlyInProduction.ts b/packages/redux-devtools-extension/src/logOnlyInProduction.ts index 68d9fb60..97442836 100644 --- a/packages/redux-devtools-extension/src/logOnlyInProduction.ts +++ b/packages/redux-devtools-extension/src/logOnlyInProduction.ts @@ -1,6 +1,12 @@ -import { compose, StoreEnhancer } from 'redux'; +import { compose } from 'redux'; +import type { StoreEnhancer } from 'redux'; import * as logOnly from './logOnly'; -import { Config, EnhancerOptions } from './index'; +import type { + Config, + EnhancerOptions, + InferComposedStoreExt, + ReduxDevtoolsExtensionCompose, +} from './index'; declare const process: { env: { @@ -10,15 +16,21 @@ declare const process: { function extensionComposeStub( config: Config -): (...funcs: StoreEnhancer[]) => StoreEnhancer; -function extensionComposeStub(...funcs: StoreEnhancer[]): StoreEnhancer; -function extensionComposeStub(...funcs: [Config] | StoreEnhancer[]) { +): []>( + ...funcs: StoreEnhancers +) => StoreEnhancer>; +function extensionComposeStub< + StoreEnhancers extends readonly StoreEnhancer[] +>( + ...funcs: StoreEnhancers +): StoreEnhancer>; +function extensionComposeStub(...funcs: [Config] | StoreEnhancer[]) { if (funcs.length === 0) return undefined; if (typeof funcs[0] === 'object') return compose; - return compose(...(funcs as StoreEnhancer[])); + return compose(...(funcs as StoreEnhancer[])); } -export const composeWithDevTools = +export const composeWithDevTools: ReduxDevtoolsExtensionCompose = process.env.NODE_ENV === 'production' ? logOnly.composeWithDevTools : typeof window !== 'undefined' &&