Error "not assignable to parameter of type never" in TypeScript: causes and solution
Hi! I started learning TypeScript and encountered a strange error that I can't understand.\n\nI have a simple code where I'm trying to filter an array by removing null and undefined values:\n\n```typescript\nconst items: (string | null | undefined)[] = ['hello', null, 'world', undefined];\n\nconst filteredItems = items.filter(item => item !== null && item !== undefined);\nconsole.log(filteredItems); // Expected: ['hello', 'world']\n```\n\nBut TypeScript throws an error: `Argument of type '(item: string | null | undefined) => boolean' is not assignable to parameter of type '(value: string | null | undefined, index: number, array: (string | null | undefined)[]) => value is never'`.\n\nI tried different approaches, for example, explicitly specifying the type for `filteredItems`, but the error persists. What does
No answers yet.
Log in to leave an answer