diff --git a/.eslintrc b/.eslintrc index afacdf656..05bd4959c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,10 +11,16 @@ "react": { "version": "detect" }, - "import/ignore": ["react-native"], + "import/ignore": [ + "react-native" + ], "import/resolver": { "node": { - "extensions": [".js", ".ts", ".tsx"] + "extensions": [ + ".js", + ".ts", + ".tsx" + ] } } }, @@ -38,12 +44,26 @@ "react/jsx-wrap-multilines": 2, "react/no-string-refs": 0, "no-unused-vars": "off", - "@typescript-eslint/no-unused-vars": ["error"], + "@typescript-eslint/no-unused-vars": [ + "error" + ], "no-redeclare": "off", - "@typescript-eslint/no-redeclare": ["error"] + "@typescript-eslint/no-redeclare": [ + "error" + ], + "@typescript-eslint/consistent-type-imports": [ + "error", + { + "prefer": "type-imports" + } + ] }, - "plugins": ["@typescript-eslint", "import", "react"], + "plugins": [ + "@typescript-eslint", + "import", + "react" + ], "globals": { "JSX": true } -} +} \ No newline at end of file diff --git a/src/components/Provider.tsx b/src/components/Provider.tsx index 4ce5d5b54..3d8bdf75c 100644 --- a/src/components/Provider.tsx +++ b/src/components/Provider.tsx @@ -1,8 +1,10 @@ -import React, { Context, ReactNode, useMemo } from 'react' -import { ReactReduxContext, ReactReduxContextValue } from './Context' +import type { Context, ReactNode } from 'react' +import React, { useMemo } from 'react' +import type { ReactReduxContextValue } from './Context' +import { ReactReduxContext } from './Context' import { createSubscription } from '../utils/Subscription' import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect' -import { Action, AnyAction, Store } from 'redux' +import type { Action, AnyAction, Store } from 'redux' import type { CheckFrequency } from '../hooks/useSelector' export interface ProviderProps { diff --git a/src/components/connect.tsx b/src/components/connect.tsx index 5e318a5c4..77fb273d2 100644 --- a/src/components/connect.tsx +++ b/src/components/connect.tsx @@ -1,6 +1,7 @@ /* eslint-disable valid-jsdoc, @typescript-eslint/no-unused-vars */ import hoistStatics from 'hoist-non-react-statics' -import React, { ComponentType, useContext, useMemo, useRef } from 'react' +import type { ComponentType } from 'react' +import React, { useContext, useMemo, useRef } from 'react' import { isValidElementType, isContextConsumer } from 'react-is' import type { Store } from 'redux' @@ -14,27 +15,29 @@ import type { ConnectPropsMaybeWithoutContext, } from '../types' -import defaultSelectorFactory, { +import type { MapStateToPropsParam, MapDispatchToPropsParam, MergeProps, MapDispatchToPropsNonObject, SelectorFactoryOptions, } from '../connect/selectorFactory' +import defaultSelectorFactory from '../connect/selectorFactory' import { mapDispatchToPropsFactory } from '../connect/mapDispatchToProps' import { mapStateToPropsFactory } from '../connect/mapStateToProps' import { mergePropsFactory } from '../connect/mergeProps' -import { createSubscription, Subscription } from '../utils/Subscription' +import type { Subscription } from '../utils/Subscription' +import { createSubscription } from '../utils/Subscription' import { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect' import shallowEqual from '../utils/shallowEqual' import warning from '../utils/warning' -import { - ReactReduxContext, +import type { ReactReduxContextValue, ReactReduxContextInstance, } from './Context' +import { ReactReduxContext } from './Context' import type { uSES } from '../utils/useSyncExternalStore' import { notInitialized } from '../utils/useSyncExternalStore' diff --git a/src/connect/wrapMapToProps.ts b/src/connect/wrapMapToProps.ts index 5b8387368..9dad1e74a 100644 --- a/src/connect/wrapMapToProps.ts +++ b/src/connect/wrapMapToProps.ts @@ -1,6 +1,6 @@ -import { ActionCreatorsMapObject, Dispatch, ActionCreator } from 'redux' +import type { ActionCreatorsMapObject, Dispatch, ActionCreator } from 'redux' -import { FixTypeLater } from '../types' +import type { FixTypeLater } from '../types' import verifyPlainObject from '../utils/verifyPlainObject' type AnyState = { [key: string]: any } diff --git a/src/hooks/useDispatch.ts b/src/hooks/useDispatch.ts index ef22881bb..f747e1baa 100644 --- a/src/hooks/useDispatch.ts +++ b/src/hooks/useDispatch.ts @@ -1,10 +1,8 @@ -import { Action, AnyAction, Dispatch } from 'redux' -import { Context } from 'react' +import type { Action, AnyAction, Dispatch } from 'redux' +import type { Context } from 'react' -import { - ReactReduxContext, - ReactReduxContextValue, -} from '../components/Context' +import type { ReactReduxContextValue } from '../components/Context' +import { ReactReduxContext } from '../components/Context' import { useStore as useDefaultStore, createStoreHook } from './useStore' /** diff --git a/src/hooks/useStore.ts b/src/hooks/useStore.ts index cf5d8868b..1d92e397e 100644 --- a/src/hooks/useStore.ts +++ b/src/hooks/useStore.ts @@ -1,12 +1,10 @@ -import { Context } from 'react' -import { Action as BasicAction, AnyAction, Store } from 'redux' +import type { Context } from 'react' +import type { Action as BasicAction, AnyAction, Store } from 'redux' +import type { ReactReduxContextValue } from '../components/Context' +import { ReactReduxContext } from '../components/Context' import { - ReactReduxContext, - ReactReduxContextValue, -} from '../components/Context' -import { - createReduxContextHook, useReduxContext as useDefaultReduxContext, + createReduxContextHook, } from './useReduxContext' /** diff --git a/src/types.ts b/src/types.ts index 90c24b951..5a1f0c4c6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,17 +1,17 @@ -import { +import type { ClassAttributes, ComponentClass, ComponentType, FunctionComponent, } from 'react' -import { Action, AnyAction, Dispatch } from 'redux' +import type { Action, AnyAction, Dispatch } from 'redux' import type { NonReactStatics } from 'hoist-non-react-statics' import type { ConnectProps } from './components/connect' -import { UseSelectorOptions } from './hooks/useSelector' +import type { UseSelectorOptions } from './hooks/useSelector' export type FixTypeLater = any diff --git a/src/utils/bindActionCreators.ts b/src/utils/bindActionCreators.ts index fa50581bc..0d5f3d8a7 100644 --- a/src/utils/bindActionCreators.ts +++ b/src/utils/bindActionCreators.ts @@ -1,4 +1,4 @@ -import { ActionCreatorsMapObject, Dispatch } from 'redux' +import type { ActionCreatorsMapObject, Dispatch } from 'redux' export default function bindActionCreators( actionCreators: ActionCreatorsMapObject, diff --git a/test/components/Provider.spec.tsx b/test/components/Provider.spec.tsx index dbb4aa95e..5bfddec3d 100644 --- a/test/components/Provider.spec.tsx +++ b/test/components/Provider.spec.tsx @@ -1,6 +1,7 @@ /*eslint-disable react/prop-types*/ -import React, { Component, Dispatch } from 'react' +import type { Dispatch } from 'react' +import React, { Component } from 'react' import ReactDOM from 'react-dom' import { createStore } from 'redux' import { Provider, connect, ReactReduxContext } from '../../src/index' diff --git a/test/components/connect.spec.tsx b/test/components/connect.spec.tsx index 310895509..ad755768e 100644 --- a/test/components/connect.spec.tsx +++ b/test/components/connect.spec.tsx @@ -1,11 +1,11 @@ /*eslint-disable react/prop-types*/ -import React, { Component, MouseEvent } from 'react' +import React, { Component } from 'react' import { createStore, applyMiddleware } from 'redux' import { Provider as ProviderMock, connect } from '../../src/index' import * as rtl from '@testing-library/react' import '@testing-library/jest-dom/extend-expect' -import type { ReactNode, Dispatch, ElementType } from 'react' +import type { ReactNode, Dispatch, ElementType, MouseEvent } from 'react' import type { Store, Dispatch as ReduxDispatch, diff --git a/test/hooks/useSelector.spec.tsx b/test/hooks/useSelector.spec.tsx index 39d7d5a50..ae38a10bb 100644 --- a/test/hooks/useSelector.spec.tsx +++ b/test/hooks/useSelector.spec.tsx @@ -7,25 +7,25 @@ import React, { useState, useContext, } from 'react' -import { Action, createStore } from 'redux' +import { createStore } from 'redux' import * as rtl from '@testing-library/react' import { Provider, - ProviderProps, useSelector, useDispatch, shallowEqual, connect, createSelectorHook, ReactReduxContext, - Subscription, } from '../../src/index' import type { TypedUseSelectorHook, ReactReduxContextValue, + ProviderProps, + Subscription, } from '../../src/index' import type { FunctionComponent, DispatchWithoutAction, ReactNode } from 'react' -import type { Store, AnyAction } from 'redux' +import type { Store, AnyAction, Action } from 'redux' import type { UseSelectorOptions } from '../../src/hooks/useSelector' // disable checks by default