LukasL
tRPC13mo ago
2 replies
Lukas

Wrong input types derived from @effect/schema

It seems like trpc is unable to resolve the input types for a procedure I'm using.
The input is
.input(
      Schema.decodeUnknownSync(
        Schema.Struct({
          authenticated: Schema.optionalWith(Schema.Boolean, {
            default: () => false,
          }),
          limit: Schema.optionalWith(Schema.Number.pipe(Schema.nonNegative()), {
            default: () => 100,
          }),
          offset: Schema.optionalWith(
            Schema.Number.pipe(Schema.nonNegative()),
            {
              default: () => 0,
            },
          ),
          permissions: Schema.optionalWith(Schema.Array(PermissionSchema), {
            default: () => [],
          }),
          roleIds: Schema.optionalWith(Schema.Array(Schema.NonEmptyString), {
            default: () => [],
          }),
        }),
      ),
    )

And the resulting type is
input: {   readonly permissions: readonly Permission[]   readonly roleIds: readonly string[]   readonly limit: number   readonly offset: number   readonly authenticated: boolean }

This is from the webstorm hover.
Decode function type in thread (char limit)
I'm guessing for some reason, trpc get's confused specifically by the use of
optionalWith
as it works correctly with
optional

Happy to provide context and figure this out.
Was this page helpful?