Effect CommunityEC
Effect Community5mo ago
17 replies
태양

`Rpc.success` with type `Schema.Void` allows implementation to return any value

Hello everyone. I was working on @effect/rpc when I ran into an interesting case where I was able to return any kind of value from an Rpc despite notating its success variant as Schema.Void. I am not sure if this is intentional behavior as a function that returns Effect.Effect<Schema.Void> can only return Void.

Here is an example and playground link,
import { Rpc, RpcGroup } from "@effect/rpc"
import { Effect, Schema } from "effect"

class TestRpcs extends RpcGroup.make(
  Rpc.make("Test", {
    success: Schema.Void,
    error: Schema.Void,
    payload: Schema.Void
  })
) {}

const TestProcedures = TestRpcs.toLayer({
  Test: (request) => Effect.succeed(2)
//                   ^ No error
})

const TestEffect = (): Effect.Effect<Schema.Void> =>
  Effect.gen(function*() {
    return yield* Effect.succeed(2)
  })
/*
Type 'Effect<number, never, never>' is not assignable to type 'Effect<Void, never, never>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  Type 'number' is not assignable to type 'Void'.
*/
Effect Documentation
Was this page helpful?