Schema restrictions

Not every Effect Schema is valid for use in Confect. Remember that an Effect Schema looks like this:

type Schema<Type, Encoded, Context>

For Schemas used in Confect:

  • Type represents the value that you'll be operating on in your code. Any TypeScript type is permitted here.

  • Encoded represents the value that is stored in the database or provided as an argument/returned as a value in a Convex function. This must be a valid Convex value.

  • Context is not currently supported. It should always be never.

Additional caveats

No-op returns from Convex functions

Unlike with the vanilla APIs, Convex functions defined with Confect may not return undefined or void—use null (Schema.Null as the returns validator) instead. Convex coerces undefined/void returns to null anyways—this just makes that more explicit.

export const myQuery = query({
    args: Schema.Struct({}),
    returns: Schema.Null,
    handler: () => Effect.succeed(null),
})
export const myQuery = query({
    args: Schema.Struct({}),
    returns: Schema.Undefined,
    handler: () => Effect.succeed(undefined),
})
export const myQuery = query({
    args: Schema.Struct({}),
    returns: Schema.Void,
    handler: () => Effect.void,
})

Last updated