PRINCESSELSA
PRINCESSELSA
TtRPC
Created by PRINCESSELSA on 3/5/2025 in #❓-help
How to wrap response type with useAsyncData from Nuxt?
I currently have this working but I'm not sure how to fix the typings so that the return type is inferred correctly as AsyncData<ReturnType> Proxy code:
function createNuxtTRPCClient(client: CreateTRPCClient<AppRouter>) {
return new Proxy(client, {
get(obj, target) {
return createNuxtTRPCClient(obj[target])
},
async apply(target, thisArg, args) {
return useAsyncData(() => target.apply(thisArg, args))
}
})
}
function createNuxtTRPCClient(client: CreateTRPCClient<AppRouter>) {
return new Proxy(client, {
get(obj, target) {
return createNuxtTRPCClient(obj[target])
},
async apply(target, thisArg, args) {
return useAsyncData(() => target.apply(thisArg, args))
}
})
}
2 replies