Получение eslint (no-unused-vars) в Redux с Typescript - PullRequest
0 голосов
/ 21 марта 2020

Я получаю исключение eslint (no-unused-vars) при разработке приложения React / Redux с Typescript. Даже если импортированная переменная использовалась в приведенной ниже функции.

actions.ts

import { User, FETCH_USERS, FETCH_USERS_SUCCESS } from './types';

export function fetchUsers() {
  return {
    type: FETCH_USERS,
  };
}

export function fetchUsersSuccess(users: User[]) {
  return {
    type: FETCH_USERS_SUCCESS,
    payload: users,
  };
}

types.ts

export const FETCH_USERS = 'FETCH_USERS';
export const FETCH_USERS_SUCCESS = 'FETCH_USERS_SUCCESS';

export interface User {
    id: number;
    email: string;
    firstName: string;
    lastName: string;
    avatar: string
}

export interface Users {
    users: User[];
    isLoading: boolean
}

interface fetchUsers {
    type: typeof FETCH_USERS;
}

interface fetchUsersSuccess {
    type: typeof FETCH_USERS_SUCCESS;
    payload: User[]
}

export type userActionTypes = fetchUsers | fetchUsersSuccess;

redurs.ts

import {
  Users, FETCH_USERS, FETCH_USERS_SUCCESS, userActionTypes,
} from './types';

const initialState: Users = {
  users: [],
  isLoading: true,
};

export default function usersReducer(
  state = initialState,
  action: userActionTypes,
): Users {
  switch (action.type) {
    case FETCH_USERS:
      return {
        ...state,
        isLoading: true,
      };
    case FETCH_USERS_SUCCESS:
      return {
        users: [...state.users, ...action.payload],
        isLoading: false,
      };
    default:
      return state;
  }
}

Получение ниже исключения в actions.ts

'User' is defined but never used.

User is imported

User being used

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...