I keep getting this error and I'm not sure what to do?[1] [1]: https://i.stack.imgur.com/mQ3Xo.png
Asked
Active
Viewed 41 times
-1
-
3Add a type to `cartItems`: `cartItems: Product[] = [];` And: please do not post images of code. – pzaenger May 02 '22 at 15:33
-
1please add code and error to OP – depperm May 02 '22 at 15:33
-
1`[]` is inferred as `never[]`, so you have to add a type like @pzaenger suggested. – kelsny May 02 '22 at 15:34
-
1Does this answer your question? [What is "not assignable to parameter of type never" error in TypeScript?](https://stackoverflow.com/questions/52423842/what-is-not-assignable-to-parameter-of-type-never-error-in-typescript) – depperm May 02 '22 at 15:34
-
Thanks so much, I'll try to be better, @pzaenger – cin vasile May 02 '22 at 15:51
1 Answers
0
you should type the array
private cartItems = [] as Product[];
per typescript eslint default rules https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/prefer-as-const.md

Shay
- 1,245
- 7
- 14
-
1I would prefer pzaenger's suggested syntax: `cartItems: Product[] = [];` – paulsm4 May 02 '22 at 16:42