From c8d4878f3da54bf8a5529c46c035d9a24c84c14f Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Mon, 4 Dec 2023 08:43:44 -0500 Subject: [PATCH] Drop the extend-redux addition --- extend-redux.d.ts | 44 ---------- package.json | 7 +- .../typescript_extended/extended-redux.ts | 88 ------------------- 3 files changed, 1 insertion(+), 138 deletions(-) delete mode 100644 extend-redux.d.ts delete mode 100644 typescript_test/typescript_extended/extended-redux.ts diff --git a/extend-redux.d.ts b/extend-redux.d.ts deleted file mode 100644 index 85aa60f..0000000 --- a/extend-redux.d.ts +++ /dev/null @@ -1,44 +0,0 @@ -import type { Action, UnknownAction, ActionCreatorsMapObject } from 'redux' -import type { ThunkAction } from './src/index' - -/** - * Globally alter the Redux `bindActionCreators` and `Dispatch` types to assume - * that the thunk middleware always exists, for ease of use. - * This is kept as a separate file that may be optionally imported, to - * avoid polluting the default types in case the thunk middleware is _not_ - * actually being used. - * - * To add these types to your app: - * import 'redux-thunk/extend-redux' - */ -declare module 'redux' { - /** - * Overload for bindActionCreators redux function, returns expects responses - * from thunk actions - */ - // TODO Fix this post-3.0.1 - // export function bindActionCreators< - // ActionCreators extends ActionCreatorsMapObject - // >( - // actionCreators: ActionCreators, - // dispatch: Dispatch - // ): { - // [ActionCreatorName in keyof ActionCreators]: ReturnType< - // ActionCreators[ActionCreatorName] - // > extends ThunkAction - // ? ( - // ...args: Parameters - // ) => ReturnType> - // : ActionCreators[ActionCreatorName] - // } - - /* - * Overload to add thunk support to Redux's dispatch() function. - * Useful for react-redux or any other library which could use this type. - */ - export interface Dispatch { - ( - thunkAction: ThunkAction - ): ReturnType - } -} diff --git a/package.json b/package.json index 6c47aa4..5ef40b9 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,6 @@ "types": "./dist/redux-thunk.d.ts", "import": "./dist/redux-thunk.mjs", "default": "./dist/cjs/redux-thunk.cjs" - }, - "./extend-redux": { - "types": "./extend-redux.d.ts" } }, "sideEffects": false, @@ -42,9 +39,7 @@ "lint": "eslint \"{src,test,typescript_test}/**/*.{js,ts}\"", "test": "vitest run", "test:cov": "vitest run --coverage", - "test:typescript": "yarn test:typescript:main && yarn test:typescript:extended", - "test:typescript:main": "tsc --noEmit -p typescript_test/tsconfig.json", - "test:typescript:extended": "tsc --noEmit -p typescript_test/typescript_extended/tsconfig.json", + "test:typescript": "tsc --noEmit -p typescript_test/tsconfig.json", "build": "tsup", "prepack": "yarn build" }, diff --git a/typescript_test/typescript_extended/extended-redux.ts b/typescript_test/typescript_extended/extended-redux.ts deleted file mode 100644 index 9a0106a..0000000 --- a/typescript_test/typescript_extended/extended-redux.ts +++ /dev/null @@ -1,88 +0,0 @@ -// This file tests behavior of types when we import the additional "extend-redux" module, -// which globally alters the Redux `bindActionCreators` and `Dispatch` types to assume -// that the thunk middleware always exists - -import { - applyMiddleware, - bindActionCreators, - createStore, - Dispatch -} from 'redux' - -import { thunk } from '../../src/index' -import type { - ThunkAction, - ThunkActionDispatch, - ThunkDispatch, - ThunkMiddleware -} from '../../src/index' - -// MAGIC: Import a TS file that extends the `redux` module types -// This file must be kept separate from the primary typetest file to keep from -// polluting the type definitions over there -import '../../extend-redux' - -export type State = { - foo: string -} - -export type Actions = { type: 'FOO' } | { type: 'BAR'; result: number } - -export type ThunkResult = ThunkAction - -export const initialState: State = { - foo: 'foo' -} - -export function fakeReducer( - state: State = initialState, - action: Actions -): State { - return state -} - -export const store = createStore( - fakeReducer, - applyMiddleware(thunk as ThunkMiddleware) -) - -export function anotherThunkAction(): ThunkResult { - return (dispatch, getState) => { - dispatch({ type: 'FOO' }) - return 'hello' - } -} - -function promiseThunkAction(): ThunkResult> { - return async (dispatch, getState) => { - dispatch({ type: 'FOO' }) - return false - } -} - -const standardAction = () => ({ type: 'FOO' }) - -interface ActionDispatchs { - anotherThunkAction: ThunkActionDispatch - promiseThunkAction: ThunkActionDispatch - standardAction: typeof standardAction -} - -// test that bindActionCreators correctly returns actions responses of ThunkActions -// also ensure standard action creators still work as expected. -// Unlike the main file, this declaration should compile okay because we've imported -// the global module override -// const actions: ActionDispatchs = bindActionCreators( -// { -// anotherThunkAction, -// promiseThunkAction, -// standardAction -// }, -// store.dispatch -// ) - -// const untypedStore = createStore(fakeReducer, applyMiddleware(thunk)) - -// // Similarly, both of these declarations should pass okay as well -// untypedStore.dispatch(anotherThunkAction()) -// untypedStore.dispatch(promiseThunkAction()).then(() => Promise.resolve())