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 { compose } from 'redux';
import { Config, EnhancerOptions } from './index'; import type { StoreEnhancer } from 'redux';
import type {
Config,
EnhancerOptions,
InferComposedStoreExt,
ReduxDevtoolsExtensionCompose,
} from './index';
declare const process: { declare const process: {
env: { env: {
@ -9,15 +15,21 @@ declare const process: {
function extensionComposeStub( function extensionComposeStub(
config: Config config: Config
): (...funcs: StoreEnhancer[]) => StoreEnhancer; ): <StoreEnhancers extends readonly StoreEnhancer<unknown>[]>(
function extensionComposeStub(...funcs: StoreEnhancer[]): StoreEnhancer; ...funcs: StoreEnhancers
function extensionComposeStub(...funcs: [Config] | StoreEnhancer[]) { ) => 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 (funcs.length === 0) return undefined;
if (typeof funcs[0] === 'object') return compose; 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' && process.env.NODE_ENV !== 'production' &&
typeof window !== 'undefined' && typeof window !== 'undefined' &&
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__

View File

@ -1,5 +1,6 @@
import Immutable from 'immutable'; import type Immutable from 'immutable';
import { Action, ActionCreator, compose, StoreEnhancer } from 'redux'; import { compose } from 'redux';
import type { Action, ActionCreator, StoreEnhancer } from 'redux';
export interface EnhancerOptions { export interface EnhancerOptions {
/** /**

View File

@ -1,13 +1,13 @@
import assign from './utils/assign'; import assign from './utils/assign';
import { import { compose } from 'redux';
import type {
Action, Action,
compose,
Dispatch, Dispatch,
PreloadedState, PreloadedState,
Reducer, Reducer,
StoreEnhancer, StoreEnhancer,
} from 'redux'; } from 'redux';
import { Config, EnhancerOptions } from './index'; import type { Config, EnhancerOptions, InferComposedStoreExt } from './index';
function enhancer(options?: EnhancerOptions): StoreEnhancer { function enhancer(options?: EnhancerOptions): StoreEnhancer {
const config: Config = options || {}; const config: Config = options || {};
@ -40,20 +40,28 @@ function enhancer(options?: EnhancerOptions): StoreEnhancer {
} }
function composeWithEnhancer(config?: EnhancerOptions) { function composeWithEnhancer(config?: EnhancerOptions) {
return function (...funcs: StoreEnhancer[]) { return function (...funcs: StoreEnhancer<unknown>[]) {
return compose(compose(...funcs), enhancer(config)); return compose(compose(...funcs), enhancer(config));
}; };
} }
export function composeWithDevTools( export function composeWithDevTools(
config: Config config: Config
): (...funcs: StoreEnhancer[]) => StoreEnhancer; ): <StoreEnhancers extends readonly StoreEnhancer<unknown>[]>(
export function composeWithDevTools(...funcs: StoreEnhancer[]): StoreEnhancer; ...funcs: StoreEnhancers
export function composeWithDevTools(...funcs: [Config] | StoreEnhancer[]) { ) => 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 (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__) {
if (funcs.length === 0) return enhancer(); if (funcs.length === 0) return enhancer();
if (typeof funcs[0] === 'object') return composeWithEnhancer(funcs[0]); 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; 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 * as logOnly from './logOnly';
import { Config, EnhancerOptions } from './index'; import type {
Config,
EnhancerOptions,
InferComposedStoreExt,
ReduxDevtoolsExtensionCompose,
} from './index';
declare const process: { declare const process: {
env: { env: {
@ -10,15 +16,21 @@ declare const process: {
function extensionComposeStub( function extensionComposeStub(
config: Config config: Config
): (...funcs: StoreEnhancer[]) => StoreEnhancer; ): <StoreEnhancers extends readonly StoreEnhancer<unknown>[]>(
function extensionComposeStub(...funcs: StoreEnhancer[]): StoreEnhancer; ...funcs: StoreEnhancers
function extensionComposeStub(...funcs: [Config] | StoreEnhancer[]) { ) => 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 (funcs.length === 0) return undefined;
if (typeof funcs[0] === 'object') return compose; 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' process.env.NODE_ENV === 'production'
? logOnly.composeWithDevTools ? logOnly.composeWithDevTools
: typeof window !== 'undefined' && : typeof window !== 'undefined' &&