diff --git a/package.json b/package.json index d075937..83d5ee9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "redux-first-history", - "version": "5.0.9", + "version": "5.0.10", "description": "Redux First History - Redux history binding support react-router - @reach/router - wouter", "main": "build/es5/index.js", "module": "build/es6/index.js", @@ -50,7 +50,7 @@ "@testing-library/react": "^12.1.0", "@types/history": "^4.7.9", "@types/jest": "^27.0.2", - "@types/reach__router": "^1.3.9", + "@types/reach__router": "^1.3.10", "@types/react": "^17.0.24", "@typescript-eslint/eslint-plugin": "^4.31.2", "@typescript-eslint/parser": "^4.31.2", diff --git a/src/create.ts b/src/create.ts index d558b7e..d5796a4 100644 --- a/src/create.ts +++ b/src/create.ts @@ -1,6 +1,6 @@ import type { History, Location } from 'history'; -import type { History as ReachHistory } from '@reach/router'; import type { Middleware, Reducer, Store } from 'redux'; +import type { ReachHistory } from './reachify.types'; import { go, goBack, diff --git a/src/reachify.ts b/src/reachify.ts index 1bf6509..0f842b7 100644 --- a/src/reachify.ts +++ b/src/reachify.ts @@ -1,6 +1,6 @@ // eslint-disable-next-line import/no-unresolved -import { History as ReachHistory } from '@reach/router'; import { History } from 'history'; +import { ReachHistory } from './reachify.types'; export const reachify = (reduxHistory: History & { listenObject: boolean }): ReachHistory => { let transitioning = false; diff --git a/src/reachify.types.ts b/src/reachify.types.ts new file mode 100644 index 0000000..6083c01 --- /dev/null +++ b/src/reachify.types.ts @@ -0,0 +1,40 @@ +// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/reach__router/index.d.ts +/** + * cloning reach router types so the packages does not depends on reach/router types if not used. + * to be removed in v6 and deprecate reach-router + */ + +interface HLocation { + pathname: string; + search: string; + state: S; + hash: string; + key?: string | undefined; +} +type WindowLocation = Window['location'] & HLocation; + +type HistoryActionType = 'PUSH' | 'POP'; +type HistoryLocation = WindowLocation & { state?: any }; +interface HistoryListenerParameter { + location: HistoryLocation; + action: HistoryActionType; +} +type HistoryListener = (parameter: HistoryListenerParameter) => void; +type HistoryUnsubscribe = () => void; + +interface NavigateOptions { + state?: TState | undefined; + replace?: boolean | undefined; +} +interface NavigateFn { + // eslint-disable-next-line @typescript-eslint/ban-types + (to: string, options?: NavigateOptions<{}>): Promise; + (to: number): Promise; +} + +export interface ReachHistory { + readonly location: HistoryLocation; + readonly transitioning: boolean; + listen: (listener: HistoryListener) => HistoryUnsubscribe; + navigate: NavigateFn; +} diff --git a/yarn.lock b/yarn.lock index d71f2b0..5131bf9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -751,10 +751,10 @@ resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11" integrity sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ== -"@types/reach__router@^1.3.9": - version "1.3.9" - resolved "https://registry.yarnpkg.com/@types/reach__router/-/reach__router-1.3.9.tgz#d3aaac0072665c81063cc6c557c18dadd642b226" - integrity sha512-N6rqQqTTAV/zKLfK3iq9Ww3wqCEhTZvsilhl0zI09zETdVq1QGmJH6+/xnj8AFUWIrle2Cqo+PGM/Ltr1vBb9w== +"@types/reach__router@^1.3.10": + version "1.3.10" + resolved "https://registry.yarnpkg.com/@types/reach__router/-/reach__router-1.3.10.tgz#141d500213a452d9d9d71d5ad96c4104094f55a3" + integrity sha512-iHAFGaVOrWi00/q7oBybggGsz5TOmwOW4M1H9sT7i9lly4qFC8XOgsdf6jUsoaOz2sknFHALEtZqCoDbokdJ2Q== dependencies: "@types/react" "*"