Array.map() not returning expected values in TypeScript with strict null checks enabled
I'm a bit lost with I'm updating my dependencies and Could someone explain I've looked through the documentation and I'm still confused about I am working with an scenario with the `Array.map()` function in TypeScript, particularly when strict null checks are enabled (using TypeScript 4.5). I have a function that processes an array of objects, and I expect it to transform the objects into a different structure. However, the output array contains many `undefined` values, which is unexpected. Here's a simplified version of the code: ```typescript interface User { id: number; name: string; email?: string; } const users: User[] = [ { id: 1, name: 'Alice' }, { id: 2, name: 'Bob', email: 'bob@example.com' }, { id: 3, name: 'Charlie' }, ]; const userEmails: string[] = users.map(user => { return user.email || null; }); ``` I expected `userEmails` to be `['null', 'bob@example.com', 'null']`, but it ends up as `['null', undefined, 'null']`. The `undefined` values are causing issues later on when I try to filter out the nulls for further processing. I thought using `user.email || null` would handle cases where the email is undefined, but it seems to be returning `undefined` instead. I also tried using a type assertion like this: ```typescript const userEmails: string[] = users.map(user => { return user.email as string || null; }); ``` This didn't work either and instead raised a compile-time behavior because `user.email` could possibly be `undefined`. Is there a better way to achieve this without running into `undefined` values in the resulting array? Should I consider a different approach or pattern to handle such scenarios, especially with strict null checks in place? This is part of a larger application I'm building. How would you solve this? This is for a microservice running on Ubuntu 22.04. Thanks for any help you can provide! What am I doing wrong? This is part of a larger web app I'm building. Is there a better approach?