theo (t3.gg)
theo (t3.gg)
Explore posts from servers
TTCTheo's Typesafe Cult
Created by theo (t3.gg) on 4/16/2023 in #questions
Mapped Types Not Inferring From Promise Correctly
TS mapped types not behaving as expected on promise inference Desired DX
export const FileRouter = UploadThingServerHelper({
someKey: {
middleware: async (req) => {
const user = await auth(req);

if (!user.userId) throw new Error("someProperty is required");

return { userIds: user.userId };
},
onUpload: async (request) => {
console.log("uploaded with the following metadata:", request.metadata); // THIS SHOULD INFER THE TYPE FROM THE RETURN
},
},
});
export const FileRouter = UploadThingServerHelper({
someKey: {
middleware: async (req) => {
const user = await auth(req);

if (!user.userId) throw new Error("someProperty is required");

return { userIds: user.userId };
},
onUpload: async (request) => {
console.log("uploaded with the following metadata:", request.metadata); // THIS SHOULD INFER THE TYPE FROM THE RETURN
},
},
});
Package types
type UploadableInputParams<TMiddlewareResponse> = {
middleware: (request: Request) => Promise<TMiddlewareResponse>;
onUpload: (response: {
metadata: TMiddlewareResponse;
}) => void;
};

export const UploadThingServerHelper = <TValidRoutes>(
input: {
readonly [K in keyof TValidRoutes]: UploadableInputParams<TValidRoutes[K]>;
},
config?: { callbackUrl?: string }
) => {...businessLogic};
type UploadableInputParams<TMiddlewareResponse> = {
middleware: (request: Request) => Promise<TMiddlewareResponse>;
onUpload: (response: {
metadata: TMiddlewareResponse;
}) => void;
};

export const UploadThingServerHelper = <TValidRoutes>(
input: {
readonly [K in keyof TValidRoutes]: UploadableInputParams<TValidRoutes[K]>;
},
config?: { callbackUrl?: string }
) => {...businessLogic};
Currently have "unknown" coming through in the onUpload type. If I manually define the type on request (i.e. onUpload: async (request: {metadata: {userId: string}})), it will "backfill" correctly Failing to get the type to infer off Promise<T> to the onUpload input
162 replies
TTCTheo's Typesafe Cult
Created by theo (t3.gg) on 9/17/2022 in #questions
How do I ONLY call my tRPC queries when a condition is met?
1. You might be looking for useMutation - https://tanstack.com/query/v4/docs/reference/useMutation?from=reactQueryV3&original=https://react-query-v3.tanstack.com/reference/useMutation 2. If you're NOT looking for useMutation, you were probably looking for the enabled key - https://tanstack.com/query/v4/docs/guides/disabling-queries#lazy-queries THIS QUESTION IS ASKED A LOT SO I DECIDED TO ANSWER IT AHEAD OF TIME
1 replies
TTCTheo's Typesafe Cult
Created by theo (t3.gg) on 9/17/2022 in #questions
WELCOME FRIENDS
We're going to be rolling out this forum soon maybe. Lmk what you think!
9 replies
TTCTheo's Typesafe Cult
Created by theo (t3.gg) on 9/17/2022 in #questions
Let's try forums
I'm curious enough so here we are
8 replies