T
Join ServertRPC
❓-help
How to infer types from input?
When I call my procedure from the client I send an array of strings as an input. How can I infer the strings so they are returned in the response (see client code comment)
On server:
On client:
On server:
example: publicProcedure
.input(z.object({ names: z.array(z.string()) }))
.query(({ input }) => {
return input.names.reduce((acc, name) => {
return {
...acc,
[name]: Math.random(),
};
}, {});
}),
On client:
const { data } = trpc.router.example.useQuery({
names: ["Hello", "World"]
})
// infer types from query input / autocomplete
const { Hello, World } = data
I think this is only for getting the response- or the input types. What I want for example:
const {.data } = trpc.example.useQuery(['one', 'two'])
// type of data variable
// readonly ["one", "two"] <- infered from input