6

ESLint is not recognizing Partial of typescript but the compiled module does not give any error.

const initialState: IAuthState = {
  authenticated: false,
  processing: false,
};

const authReducer = (state: IAuthState = initialState, action: any): IAuthState => {
  const State = (newState: Partial<IAuthState>): IAuthState => ({...state, ...newState});

  switch (action.type) {
    case Actions.SIGN_IN_PROCESS_INITIATED:
      return State({processing: true});

    case Actions.SIGN_IN_PROCESS_FAILED:
      return State({processing: false});

    default:
      return state;
  }
};

I know that this can be suppressed by // eslint-disable-next-line no-undef but still, I want an explanation for this and a permanent solution so that I dont get this not so error Error.

Faisal Manzer
  • 2,089
  • 3
  • 14
  • 34

2 Answers2

8

I had a similar case some time ago and fixed it by installing @typescript-eslint/parser as devDependency and including it in eslint config:

  "extends": [..., "@typescript-eslint/parser"],
winiar
  • 174
  • 1
  • 4
  • 8
    documentation says it needs to be used as `parser` not `extends` in eslint config, like this: "parser": "@typescript-eslint/parser" – jamland Apr 28 '20 at 15:15
0

After experimenting with other configuration parameters for compilerOptions one-by-one, I found out the problem for me was that I didn't have esnext listed under compilerOptions.lib.

{
  "compilerOptions": {
    // other config
    "lib": [
      "dom",
      "dom.iterable",
      "esnext" // I added this to ensure `Partial`, `Record`, and others were recognized as defined by ESLint
    ]
    // other config
  }
}
CopyLeft
  • 321
  • 4
  • 6