Coder Lam
Coder Lam

Reputation: 425

Array is not assignable to type 'never[]'

enter image description hereCould use some help figuring out why the type here is never or never[]

const effects: EFFECT_TYPES[] = editState === EDITSTATES.EDIT ? currentEffects : draftEffects;
  const currentImageUrl = urlFromEffects({
    baseURL: imageUrl,
    effects,
  });

throws Type 'EFFECT_TYPES[]' is not assignable to type 'never[]'. Type 'EFFECT_TYPES' is not assignable to type 'never'.ts(2322)

typescript error underlined

Upvotes: 0

Views: 171

Answers (1)

Elias Schablowski
Elias Schablowski

Reputation: 2812

The problem is that TypeScript incorrectly inferred the type of effects to be never, the remedy being to define the type of effects manually:

export const urlFromEffects = ({ baseURL, effects = []}: {
  baseURL: string;
  effects?: EFFECT_TYPES[];
}) => {
  // ...
}

Upvotes: 1

Related Questions