Issue with Error Inference in Effect Program

Hello! 👋

Could someone please help me with my program?

import { Effect, Schema, Data } from 'effect'
import { HttpClient, HttpClientRequest, HttpClientResponse } from '@effect/platform';
import { NodeHttpClient } from '@effect/platform-node';

const TodoResponseSchema = Schema.Struct({
    userId: Schema.Int,
    id: Schema.Int,
    title: Schema.String,
    completed: Schema.Boolean,
})

class UnknownError extends Data.TaggedError('UnknownError')<{}> {}

const program = Effect.gen(function* () {
    const client = yield* HttpClient.HttpClient

    const response = HttpClientRequest.get('https://jsonplaceholder.typicode.com/todos/1').pipe(
        HttpClientRequest.acceptJson,
        client.execute,
        Effect.flatMap(HttpClientResponse.matchStatus({
            200: HttpClientResponse.schemaBodyJson(TodoResponseSchema),
            orElse: () => Effect.fail(new UnknownError()),
        })),
    )

    console.log(response) // response has type Effect.Effect<{ ... }, unknown, never>
})

const runnable = program.pipe(
    Effect.provide(NodeHttpClient.layer)
)

Effect.runPromise(runnable).catch(console.error)


See the console.log statement. The response does not have inferred error correctly. Why is that? If I remove the line with 200: HttpClientResponse.schemaBodyJson(TodoResponseSchema), it will infer the error type correctly. But why is that? 🤔

Thanks!
Was this page helpful?