Skip to content

Commit

Permalink
Merge pull request #4383 from raulsanchez1024/enable-prefer-type-only…
Browse files Browse the repository at this point in the history
…-imports

Enable prefer type-only imports
  • Loading branch information
EskiMojo14 committed Feb 12, 2024
2 parents 02073c4 + fc00cae commit f0593c4
Show file tree
Hide file tree
Showing 22 changed files with 44 additions and 58 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ module.exports = {
argsIgnorePattern: '^_',
varsIgnorePattern: '^_'
}
]
],
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'type-imports', disallowTypeAnnotations: false },
],
}
}
4 changes: 2 additions & 2 deletions src/applyMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import compose from './compose'
import { Middleware, MiddlewareAPI } from './types/middleware'
import { StoreEnhancer, Dispatch } from './types/store'
import type { Middleware, MiddlewareAPI } from './types/middleware'
import type { StoreEnhancer, Dispatch } from './types/store'

/**
* Creates a store enhancer that applies middleware to the dispatch method
Expand Down
4 changes: 2 additions & 2 deletions src/bindActionCreators.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Dispatch } from './types/store'
import { ActionCreator, ActionCreatorsMapObject, Action } from './types/actions'
import type { Dispatch } from './types/store'
import type { ActionCreator, ActionCreatorsMapObject, Action } from './types/actions'
import { kindOf } from './utils/kindOf'

function bindActionCreator<A extends Action>(
Expand Down
4 changes: 2 additions & 2 deletions src/combineReducers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Action } from './types/actions'
import {
import type { Action } from './types/actions'
import type {
ActionFromReducersMapObject,
PreloadedStateShapeFromReducersMapObject,
Reducer,
Expand Down
6 changes: 3 additions & 3 deletions src/createStore.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import $$observable from './utils/symbol-observable'

import {
import type {
Store,
StoreEnhancer,
Dispatch,
Observer,
ListenerCallback,
UnknownIfNonSpecific
} from './types/store'
import { Action } from './types/actions'
import { Reducer } from './types/reducers'
import type { Action } from './types/actions'
import type { Reducer } from './types/reducers'
import ActionTypes from './utils/actionTypes'
import isPlainObject from './utils/isPlainObject'
import { kindOf } from './utils/kindOf'
Expand Down
2 changes: 1 addition & 1 deletion src/types/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dispatch } from './store'
import type { Dispatch } from './store'

export interface MiddlewareAPI<D extends Dispatch = Dispatch, S = any> {
dispatch: D
Expand Down
2 changes: 1 addition & 1 deletion src/types/reducers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Action, UnknownAction } from './actions'
import type { Action, UnknownAction } from './actions'

/* reducers */

Expand Down
4 changes: 2 additions & 2 deletions src/types/store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Action, UnknownAction } from './actions'
import { Reducer } from './reducers'
import type { Action, UnknownAction } from './actions'
import type { Reducer } from './reducers'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import _$$observable from '../utils/symbol-observable'

Expand Down
11 changes: 2 additions & 9 deletions test/applyMiddleware.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import {
createStore,
applyMiddleware,
Middleware,
MiddlewareAPI,
Action,
Store,
Dispatch
} from 'redux'
import { createStore, applyMiddleware } from 'redux'
import type { Middleware, MiddlewareAPI, Action, Store, Dispatch } from 'redux'
import { vi } from 'vitest'
import * as reducers from './helpers/reducers'
import { addTodo, addTodoAsync, addTodoIfEmpty } from './helpers/actionCreators'
Expand Down
3 changes: 2 additions & 1 deletion test/bindActionCreators.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { bindActionCreators, createStore, ActionCreator, Store } from '../src'
import { bindActionCreators, createStore } from '../src'
import { ActionCreator, Store } from '../src'

Check failure on line 2 in test/bindActionCreators.spec.ts

View workflow job for this annotation

GitHub Actions / Lint, Test, Build & Pack on Node 18.x

All imports in the declaration are only used as types. Use `import type`
import { todos } from './helpers/reducers'
import * as actionCreators from './helpers/actionCreators'

Expand Down
3 changes: 1 addition & 2 deletions test/combineReducers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable no-console */
import type { Reducer, Action } from 'redux'
import {
createStore,
combineReducers,
Reducer,
Action,
__DO_NOT_USE__ActionTypes as ActionTypes
} from 'redux'
import { vi } from 'vitest'
Expand Down
13 changes: 4 additions & 9 deletions test/createStore.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import {
createStore,
combineReducers,
StoreEnhancer,
Action,
Store,
Reducer
} from 'redux'
import type { StoreEnhancer, Action, Store, Reducer } from 'redux'
import { createStore, combineReducers } from 'redux'
import { vi } from 'vitest'
import {
addTodo,
Expand All @@ -17,7 +11,8 @@ import {
unknownAction
} from './helpers/actionCreators'
import * as reducers from './helpers/reducers'
import { from, ObservableInput } from 'rxjs'
import type { ObservableInput } from 'rxjs'
import { from } from 'rxjs'
import { map } from 'rxjs/operators'
import $$observable from '../src/utils/symbol-observable'

Expand Down
4 changes: 2 additions & 2 deletions test/helpers/actionCreators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
THROW_ERROR,
UNKNOWN_ACTION
} from './actionTypes'
import { TodoAction } from './reducers'
import { Dispatch } from 'redux'
import type { TodoAction } from './reducers'
import type { Dispatch } from 'redux'

export function addTodo(text: string): TodoAction {
return { type: ADD_TODO, text }
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dispatch, Middleware } from 'redux'
import type { Dispatch, Middleware } from 'redux'

export const thunk: Middleware<{
<R>(thunk: (dispatch: Dispatch, getState: () => any) => R): R
Expand Down
4 changes: 2 additions & 2 deletions test/typescript/actionCreators.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
import type {
ActionCreator,
Action,
Dispatch,
bindActionCreators,
ActionCreatorsMapObject
} from 'redux'
import { bindActionCreators } from 'redux'

interface AddTodoAction extends Action {
text: string
Expand Down
2 changes: 1 addition & 1 deletion test/typescript/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Action as ReduxAction } from 'redux'
import type { Action as ReduxAction } from 'redux'

namespace FSA {
interface Action<P> extends ReduxAction {
Expand Down
2 changes: 1 addition & 1 deletion test/typescript/dispatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dispatch } from 'redux'
import type { Dispatch } from 'redux'

/**
* Default Dispatch type accepts any object with `type` property.
Expand Down
3 changes: 2 additions & 1 deletion test/typescript/enhancers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { StoreEnhancer, Action, Reducer, createStore } from 'redux'
import type { StoreEnhancer, Action, Reducer } from 'redux'
import { createStore } from 'redux'

interface State {
someField: 'string'
Expand Down
2 changes: 1 addition & 1 deletion test/typescript/injectedDispatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dispatch, Action } from 'redux'
import type { Dispatch, Action } from 'redux'

interface Component<P> {
props: P
Expand Down
5 changes: 2 additions & 3 deletions test/typescript/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {
import type {
Middleware,
MiddlewareAPI,
applyMiddleware,
createStore,
Dispatch,
Reducer,
Action
} from 'redux'
import { applyMiddleware, createStore } from 'redux'

/**
* Logger middleware doesn't add any extra types to dispatch, just logs actions
Expand Down
9 changes: 2 additions & 7 deletions test/typescript/reducers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import {
Reducer,
Action,
combineReducers,
ReducersMapObject,
AnyAction
} from 'redux'
import type { Reducer, Action, ReducersMapObject, AnyAction } from 'redux'
import { combineReducers } from 'redux'

/**
* Simple reducer definition with no action shape checks.
Expand Down
7 changes: 3 additions & 4 deletions test/typescript/store.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {
import { combineReducers, createStore } from 'redux'
import type {
Store,
createStore,
Reducer,
Action,
StoreEnhancer,
Unsubscribe,
Observer,
combineReducers
Observer
} from 'redux'
import 'symbol-observable'

Expand Down

0 comments on commit f0593c4

Please sign in to comment.