Error with asynchronous operation in TypeScript schema validation using Effect library

Hi guys. I was writing this schema for user profiles:

const UserProfile = Schema.Struct({
    // -- snip --
    Username: Username.Schema.pipe(
        Schema.filterEffect((s) => Effect.orElseSucceed(
            Effect.gen(function* () {
                const db = yield* GetMongoDatabase;
                const coll = db.collection<typeof UserProfile.Type>("user-profile");
               
                // const user = await coll.findOne({ Username: s }); <- This line is the important !

                if (user !== null) {
                    return "there is a user profile with that username";
                }

                return true;
            }),
            () => "unable to check the username for the user profile"
        ))
    ),
    // -- snip --


The important thing of it is the filter for the Username, the idea is to check that the username is not in use. So I use coll.findOne to search an user profile with that username (the database implementation is using mongodb). coll.findOne is an asynchronous operation, it needs await. Long story short, I tried to use this where the commented line:

const user = yield* Effect.promise(() => coll.findOne({ Username: s }));


But it breaks everthing, and the error in the editor only says:

Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.ts(7024)

Honestly I don't get it, it marks the whole callback inside Schema.filterEffect with that error.
Was this page helpful?