Fix types for other exports from extension package (#1331)

* Fix types for other imports from extension package

Missed in https://github.com/reduxjs/redux-devtools/pull/1323

* Create pink-bags-grab.md
This commit is contained in:
Nathan Bierema 2023-01-16 08:15:34 -05:00 committed by GitHub
parent 9536998256
commit a07167406a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 24 deletions

View File

@ -0,0 +1,5 @@
---
'@redux-devtools/extension': patch
---
Fix types for other exports from `@redux-devtools/extension`.

View File

@ -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[]) {
): <StoreEnhancers extends readonly StoreEnhancer<unknown>[]>(
...funcs: StoreEnhancers
) => StoreEnhancer<InferComposedStoreExt<StoreEnhancers>>;
function extensionComposeStub<
StoreEnhancers extends readonly StoreEnhancer<unknown>[]
>(
...funcs: StoreEnhancers
): StoreEnhancer<InferComposedStoreExt<StoreEnhancers>>;
function extensionComposeStub(...funcs: [Config] | StoreEnhancer<unknown>[]) {
if (funcs.length === 0) return undefined;
if (typeof funcs[0] === 'object') return compose;
return compose(...(funcs as StoreEnhancer[]));
return compose(...(funcs as StoreEnhancer<unknown>[]));
}
export const composeWithDevTools =
export const composeWithDevTools: ReduxDevtoolsExtensionCompose =
process.env.NODE_ENV !== 'production' &&
typeof window !== 'undefined' &&
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__

View File

@ -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 {
/**

View File

@ -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<unknown>[]) {
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[]) {
): <StoreEnhancers extends readonly StoreEnhancer<unknown>[]>(
...funcs: StoreEnhancers
) => StoreEnhancer<InferComposedStoreExt<StoreEnhancers>>;
export function composeWithDevTools<
StoreEnhancers extends readonly StoreEnhancer<unknown>[]
>(
...funcs: StoreEnhancers
): StoreEnhancer<InferComposedStoreExt<StoreEnhancers>>;
export function composeWithDevTools(
...funcs: [Config] | StoreEnhancer<unknown>[]
) {
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<unknown>[]));
}
if (funcs.length === 0) return undefined;

View File

@ -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[]) {
): <StoreEnhancers extends readonly StoreEnhancer<unknown>[]>(
...funcs: StoreEnhancers
) => StoreEnhancer<InferComposedStoreExt<StoreEnhancers>>;
function extensionComposeStub<
StoreEnhancers extends readonly StoreEnhancer<unknown>[]
>(
...funcs: StoreEnhancers
): StoreEnhancer<InferComposedStoreExt<StoreEnhancers>>;
function extensionComposeStub(...funcs: [Config] | StoreEnhancer<unknown>[]) {
if (funcs.length === 0) return undefined;
if (typeof funcs[0] === 'object') return compose;
return compose(...(funcs as StoreEnhancer[]));
return compose(...(funcs as StoreEnhancer<unknown>[]));
}
export const composeWithDevTools =
export const composeWithDevTools: ReduxDevtoolsExtensionCompose =
process.env.NODE_ENV === 'production'
? logOnly.composeWithDevTools
: typeof window !== 'undefined' &&