I'm facing a type Error that's confusing me
This is the state type:
export type Foo = {
animals: {
dogs?: Dogs[],
cats?: Cats[],
fishs?: Fishs[]
},
animalQueue: (Dogs | Cats | Fishs)[]
}
Now, in a reducer I'm attempting this:
...
someFunction: (state, action: PayloadAction<{ index: number, animalKey: keyof Required<Foo>['animals']}>) => {
const {index, animalKey} = action.payload
const animal = state.animalQueue[index]
state.animals[animalKey]!.push(animal)
}
...
This results in an error:
TS2345: Argument of type 'WritableDraft or WritableDraft or WritableDraft' is not assignable to parameter of type 'Dogs & Cats & Fishs. Type 'WritableDraft' is not assignable to type 'Dogs & Cats & Fishs'. Property 'height' is missing in type 'WritableDraft' but required in type 'Cats'.
I believe this is due to this:
(Dogs | Cats | Fishs)[]
What I'm trying to define here is an array that can contain Dogs
, Cats
, and/or Fishs
. Basically, a mix of all three.