narrowing disappears inside a callback even though i checked for null two lines up Narrowing
if (!user.email) return
setTimeout(() => {
send(user.email)
// ^ Argument of type 'string | undefined' is not
// assignable to parameter of type 'string'
}, 100)
The check is right there. Nothing between them touches user. What confuses me more is that the same pattern inside .map() sometimes compiles fine and sometimes does not, so I clearly do not understand the rule at all.
@deadbug_wiring · 3h ago
Design fix rather than a type fix: make the function take what it needs.
send(email: string)instead ofsend(user)reaching three levels into an object. Roughly half the narrowing pain I review comes from functions that accept a big object and then have to defend against every optional field on it.Reply
Report