Type 'Effect<{ message: string; }, CreatePasswordResetTokenError | ConfigError | CreatePasswordResetUrlError, never>' is not assignable to type 'Effect<{ readonly message: string; } | HttpServerResponse, CreatePasswordResetTokenError | CreatePasswordResetUrlError | HttpApiDecodeError | ConfigError, never>'. #5504
Replies: 1 comment
|
The type error is because your handler returns Fix: use // The handler must return the type defined in your API schema
// If your endpoint is defined as returning { message: string }:
const handler = HttpApiBuilder.handler(MyApi, "sendResetEmail", (req) =>
Effect.gen(function* () {
const token = yield* createPasswordResetToken(req.payload.email);
const url = yield* createPasswordResetUrl(token);
return { message: "Reset email sent" }; // matches schema, not HttpServerResponse
})
);Common cause — returning If your endpoint schema returns Conversely, if you need to return a custom response (e.g., redirect, set cookies), declare the endpoint as returning const MyApi = HttpApi.make("my-api").add(
HttpApiGroup.make("auth").add(
HttpApiEndpoint.post("resetPassword", "/reset")
.addSuccess(Schema.String) // or HttpServerResponse
.addError(CreatePasswordResetTokenError)
)
);The union Could you share the API schema definition? That would pinpoint exactly which return type is expected. |
Uh oh!
There was an error while loading. Please reload this page.
I am working on a Next.js project and I am trying to write the API endpoints using effect/platform.
I have run into a TS error that I am not able to solve even after consulting the LLMs.
Here is my
app/effect/[[...path]]/route.tsfile:Here is the
app/effect/server.tsfile:Here is the endpoint definition:
lib/api/auth/endpoints/index.ts:
Here is the group file:
lib/api/auth/group/index.ts:
Here is the
forgotPasswordHandlerfile:Here is the
createPasswordResetTokenfile;Here is the
passwordresetTokenUrlfunction:The Errors
Currently, I am getting two TS errors.
Error-1
I am seeing a red squiggly error under
forgotPasswordHandleron this line:The error says:
I don't know what do I do to fix this error?
Error-2
I am getting another red squiggly error under
WebHandlerLayeron the line below:The error says:
Please help me fix these errors.
Note
please note that all errors go away if I remove the following line:
from the
forgotPasswordHandlerfile.All reactions