Paweł
Paweł
TTCTheo's Typesafe Cult
Created by Paweł on 5/19/2023 in #questions
Omit properties function typescript
Hey, I'm trying to write helper function to easily omit some properties form my object, but I can't really get correct return type that omits properties i passed throught. Right now it returns object that has type of the same object i pass in parameter.
export function omit<T extends object, U extends keyof T>(obj: T, ...props: U[]) {
const result = { ...obj };
props.forEach(function (prop) {
delete result[prop];
});

return result as Omit<T, U>;
}

omit<typeof input, keyof typeof input>(input, "owner", "type");
export function omit<T extends object, U extends keyof T>(obj: T, ...props: U[]) {
const result = { ...obj };
props.forEach(function (prop) {
delete result[prop];
});

return result as Omit<T, U>;
}

omit<typeof input, keyof typeof input>(input, "owner", "type");
2 replies
TTCTheo's Typesafe Cult
Created by Paweł on 4/25/2023 in #questions
Pwa + nextauth
Hey, i was wondering if it is possible to somehow cache logged in user for 24hr or so? I wanted to create fully offline experience for user but to use app user must be in session. I use google and magic email link providers + next-pwa.
2 replies
TTCTheo's Typesafe Cult
Created by Paweł on 4/13/2023 in #questions
Trpc return stream
Hey, I'm generating pdf doc then converting it to stream and i want to return it from my endpoint, but trpc i yelling at me with this error
TRPCClientError: Unable to transform response from server
TRPCClientError: Unable to transform response from server
trpc doesn't allow to return streams? I wasn't able to find anything to clarify this in their docs or google.
3 replies
TTCTheo's Typesafe Cult
Created by Paweł on 4/3/2023 in #questions
Error of object possibly undefined
9 replies
TTCTheo's Typesafe Cult
Created by Paweł on 3/18/2023 in #questions
How to add auth property to NextComponentType
Hey, I want to add auth flag to next components to check if page should be protected. I tried extending its interface but without any success.
declare module "next" {
interface NextComponentType {
auth: boolean;
}
}
declare module "next" {
interface NextComponentType {
auth: boolean;
}
}
Here is my _app code
const MyApp: AppType<{ session: Session | null }> = ({
Component,
pageProps: { session, ...pageProps },
}) => {
return (
<SessionProvider session={session}>
{Component.auth ? (
<Auth>
<Layout>
<Component {...pageProps} />
</Layout>
</Auth>
) : (
<Component {...pageProps} />
)}
</SessionProvider>
);
};
const MyApp: AppType<{ session: Session | null }> = ({
Component,
pageProps: { session, ...pageProps },
}) => {
return (
<SessionProvider session={session}>
{Component.auth ? (
<Auth>
<Layout>
<Component {...pageProps} />
</Layout>
</Auth>
) : (
<Component {...pageProps} />
)}
</SessionProvider>
);
};
1 replies
TTCTheo's Typesafe Cult
Created by Paweł on 3/12/2023 in #questions
TRPC useContext, not seeing trpc react-query helpers
1 replies
TTCTheo's Typesafe Cult
Created by Paweł on 3/11/2023 in #questions
Manage items position field after delete
Hey, I'm working currently on todo list where user can change position of task using drag and drop. To do this i need number field on task to know on which position he is. And there is my question - if i have 5 items and someone deletes item 3 for example. should i change 4th and 5th items position to -1? I'm now using items length to set newly created task position (which isn't perfect i guess?). So, should I decrement positions that are higher than deleted one? Or there is some other solution? here is my Task schema
model Task {
id String @default(cuid())
position Int
text String
isCompleted Boolean @default(false)
user User @relation(fields: [userId], references: [id])
userId String

@@unique([id, position])
@@index([userId])
}
model Task {
id String @default(cuid())
position Int
text String
isCompleted Boolean @default(false)
user User @relation(fields: [userId], references: [id])
userId String

@@unique([id, position])
@@index([userId])
}
7 replies
TTCTheo's Typesafe Cult
Created by Paweł on 3/9/2023 in #questions
t3-stack tRPC ssr
Hey, I'm having trouble understanding how ssr works with t3 stack config. If I do trpc request inside component it makes it ssr by default? Do i understand it correctly? I haven't seen anyone using getServerSideProps so i assume it does? Can I read somewhere more details about that?
4 replies
TTCTheo's Typesafe Cult
Created by Paweł on 3/7/2023 in #questions
next-auth add sign in using github button to page instead of redirect
Hey, just like in the title, I want to add sign in button in the home page instead of default redirect page is it possible to do? Or is it just how next-auth works? Sorry if it is a stupid question but I couldn't find an answer to that.
6 replies
TTCTheo's Typesafe Cult
Created by Paweł on 3/4/2023 in #questions
Good case to use getServerSideProps instead of ISR
Hey everyone! I'm new to the next.js and i'm trying to figure out when one should use getServerSideProps instead of ISR since it is not recomended. I guess it is only viable for pages that changes data constantly, like every second?
4 replies