P
P
PeterPetrov2021-11-28 21:55:26
typescript
PeterPetrov, 2021-11-28 21:55:26

Argument like "never[] | undefined" cannot be assigned to a parameter of type "never".?

I just started learning TypeScript and I can't understand what he wants from me.
There is a certain store where user info is pushed, but TS gives an error
"Argument like "never[] | undefined" cannot be assigned to a parameter of type "never".
Type "undefined" cannot be assigned to type "never".ts(2345)"

interface IUser {
  type: string;
  payload: never[] | undefined;
}

const usersSlice = createSlice({
  name: "user",
  initialState: {
    users: [],
  },
  reducers: {
    users(state, action: IUser) {
      state.users.push(action.payload);
    },
  },
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-11-29
@Aetae

your initialState is not typed, so an array without a type is of type nexer[] - i.e. you can't put anything in it at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question