TypeScript Inference Issue with `Effect.if` and Non-Null Assertion

Something I noticed when using Effect.if is that if I check for !== undefined (the only other possible value of my variable), the onTrue: () => myVal <~ myVal is possible undefined


This shouldn't be the expected behaviour right OR is this a limitation with TS inference 🤔
return yield* Effect.if(dbEntry !== undefined, {
              // @NOTE we shouldn't need this, I am not sure why Effect doesn't guard it?
              // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
              onTrue: () => Effect.succeed(dbEntry!),
              onFalse: () =>
                Effect.fail(
                  new DbError({
                    reason: "Something has gone wrong",
                  }),
                ),
            });


This is on "effect": "3.12.7",
Was this page helpful?