Lukas
Lukas
TtRPC
Created by Lukas on 2/12/2025 in #❓-help
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: () => [],
}),
}),
),
)
.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 }
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.
3 replies
TtRPC
Created by Lukas on 1/4/2025 in #❓-help
Can I get a mutations input type form my client?
Hey friends, I'm working on an angular app with tanstack query and trpc. I'm trying to solve duplication and have one central repository (service) of query options. For this I am using a service and it would be amazing to get the input type for my procedures.
@Injectable({
providedIn: 'root',
})
export class QueriesService {
private queryClient = inject(QueryClient);
private trpcClient = injectTrpcClient();

public createTemplate(input: any) {
return () =>
mutationOptions({
mutationFn: () =>
this.trpcClient.templateCategories.create.mutate(input),
onSuccess: () => {
this.queryClient.invalidateQueries({
queryKey: ['templateCategories'],
});
},
});
}
}
@Injectable({
providedIn: 'root',
})
export class QueriesService {
private queryClient = inject(QueryClient);
private trpcClient = injectTrpcClient();

public createTemplate(input: any) {
return () =>
mutationOptions({
mutationFn: () =>
this.trpcClient.templateCategories.create.mutate(input),
onSuccess: () => {
this.queryClient.invalidateQueries({
queryKey: ['templateCategories'],
});
},
});
}
}
You can see that I'd love to use the input type where I currently have any. Looking forward to your input. EDIT: Okay I found AppRouter['templateCategories']['create']['_def']['$types']['input'] but that does not seem very nice 😅
2 replies