Handling TypeScript Error for Possibly Null `existingUser` in Effect Code

hello I'm learning effect. I have a small problem in this code:
const existingUser = yield* Effect.tryPromise({
  try: () => get_user_by_email(client, {
             email: form.data.email,
    }),
  catch: () => new ServerError({ errors: ["User not found"] }) });

if (!existingUser || !existingUser?.password || !existingUser.email) {
  yield* Effect.fail(
    new CustomInputError({ 
      form,
      field: ["email", "password"],
      message: "Incorrect Email or Password", }),
    );
  }

const isPasswordValid = yield* Effect.tryPromise({
  try: () =>   bcryptjs.compare(form.data.password, existingUser.password),
  catch: () => new ServerError({ errors:  
["Invalid password"] }) 
});

in
bcryptjs.compare(form.data.password, existingUser.password)

typescript is complaining that existingUser is possibly null even though already guard it . seems like TS does not recognize that Effect.fail returns early. what can I do?
Was this page helpful?