Creating a Generic Service Context with Dynamic Schema Types in TypeScript

I'm trying to create a generic service Context.Tag by passing the Schema to return the type according to the schema that I'm passing as a parameter. What am I doing wrong? or is this possible to do ? someone face on something similar ? thanks! effect

const make = <Name extends String, SchemaType extends S.Schema.Any>(collectionName: Name, schema: SchemaType) => 
T.gen(function* () {
    return {
        create: (dto: S.Schema.Type<SchemaType>) => pipe(
            T.tryPromise({
            try: async () => Promise.resolve({
                ...dto,
                username: 'jonh doe of ' + collectionName
            }),
            catch: () => console.log('something went wrong')
        }),
            S.decode(schema)
        )
    }
})
Was this page helpful?