s-panferov / awesome-typescript-loader

Awesome TypeScript loader for webpack
Other
2.35k stars 179 forks source link

Unclear to which lines error refers #648

Closed peterzernia closed 4 years ago

peterzernia commented 5 years ago

I'm getting the errors while setting up the useReducer hook in Reactjs

ERROR in [at-loader] ./src/reducer.ts:3:372 
    TS2554: Expected 2 arguments, but got 1.

ERROR in [at-loader] ./src/reducer.ts:16:32 
    TS2554: Expected 1 arguments, but got 3.

ERROR in [at-loader] ./src/reducer.ts:23:32 
    TS2554: Expected 1 arguments, but got 3.

The errors have to deal with calling functions with incorrect number of arguments, but strangely this whole file only has one function definition and it's not being called anywhere. The lines of code the error messages correspond to don't really make sense either. Is there something I'm missing?

reducer.js:

import { SET_USER, CLEAR_USER, RESET } from './actions'

interface Action {
  type: string;
  payload?: object;
}

interface State {
  user: object;
  authenticated: boolean;
}

export const initialState = {
  user: {},
  authenticated: false,
}

export const reducer = (state: State, action: Action): State => {
  switch (action.type) {
    case SET_USER:
      localStorage.setItem('user', JSON.stringify(action.payload))
      return { ...state, user: action.payload, authenticated: true }
    case CLEAR_USER:
      localStorage.removeItem('user')
      return { ...state, user: initialState.user, authenticated: false }
    case RESET:
      return initialState
    default:
      throw new Error()
  }
}

Lines 3, 16, 32 refer to inferface Action {, }, and case CLEAR_USER: respectively, which doesn't make any sense. Also this reducer function is called in the background by react, not actually anywhere in my code.

peterzernia commented 4 years ago

The issue came from using both awesome-typescript-loader and babel loader. Using only one of them fixes the issue.