Theo's Typesafe Cult

TTC

Theo's Typesafe Cult

Join the community to ask questions about Theo's Typesafe Cult and get answers from other members.

Join

Functions type for key of objects with specific key

Hey, are there any typescript wizards here that could help? I've been trying for a while already but don't really get there. I would like to type a function that takes in two arguments: an arbitrary object as the first argument and for the second argument a key of that object but only allow keys with e.g. a number as an associated value. What's the best way to do this? This is what I have so far. I only want to allow valueKeys which have a type number as a value. Thanks! ```ts const BarChart = <...

How to figure out how long a postgres sql query will take

Sorry for the vague q, but I find myself having to write alot of custom sql queries these days to make zapier "be our backend". Zapier will fail the zap if a query times out. But I dont know a good way to gauge at what scale we will reach 30 seconds. Here is a query in question:
SELECT "proposalId", string_agg("ProposalDateRanges"."from" || ',' || "ProposalDateRanges"."to", ';') FROM "public"."ProposalDateRanges" WHERE "ProposalDateRanges"."proposalId" = '{{169303871__id}}' GROUP by "ProposalDateRanges"."proposalId"
SELECT "proposalId", string_agg("ProposalDateRanges"."from" || ',' || "ProposalDateRanges"."to", ';') FROM "public"."ProposalDateRanges" WHERE "ProposalDateRanges"."proposalId" = '{{169303871__id}}' GROUP by "ProposalDateRanges"."proposalId"
...

Should I start with what I know, or what I don't?

I'm building an app with t3. If I can complete it, I intend to release it to the world to use. I've done a lot of frontend, some backend stuff. But when it comes to "putting it all together" I find myself a bit stumped on where to start. Part of me wants to just build out the feature/UI stuff without any really API/backend things happening. Another part of me knows that I'm avoiding doing those things because I'm unfamiliar with them and thus they are terrifying. ...

Prisma type safety

You guys have any idea what's happening here and why it's not working? https://www.prisma.io/docs/concepts/components/prisma-client/advanced-type-safety...

Order results by a nested relation's DateTime with Prisma

I have a Conversation model which has one-to-many relationship with Messages. I want to order the conversations by the most recent message, but it seems Prisma doesn't have a way to do this??? I need pagination so I can't do this after querying either, so is my only solution to write the SQL myself? I get the love for Prisma, but there are so many things missing 🙃

Prisma - Timed out fetching a new connection from the connection pool

Hi there, Sometimes, even with a very small site (nextjs, hosted on vercel), I ran into this issue: PrismaClientKnownRequestError: Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 5) Unfortunately I dont understand the suggested connection pool tuning. Any specific recommendations regarding Vercel Hosting?...

can I remove prisma and trpc from T3 app if I want to?

Hey guys so I'm buulding something with T3 , and I'm wondering if I will need prisma and trpc in this project. If not - can I just remove it? And how?

Alternative to TypeScript Classes

Currently, I'm refactoring TypeScript code into classes because I want to use extends for N features to inherit some base functionality. Previously, I had pockets of functions organized in separate files based on the type of functionality that they were providing. (foo.ts, bar.ts, baz.ts) I figured classes would be better to stay DRY, as it removes a lot of copy-paste boilerplate between every feature. (common variables + common functions) But I'm finding it really difficult to transition this structure into classes, because there are shared variables in a feature directory (variables.ts), and there is no partial keyword in TypeScript like there is in C#, so I have to stick thousands of lines of code in the same file (to avoid circular imports). ...

[Solved] Unhandled Runtime Error

i am throwing TRPCError from trpc mutation how can I handle it on the client I am getting 1 of 1 Unhandled Error

setInterval timer with state setter

Im using a setInterval as a countdown timer and there is state being set within to display the timer. Would i need to stick this setInterval within a useEffect with a empty dependency to make sure it only runs once? Or is there a better way to do this?

State Frustrations in Desktop Apps

I made an electron app recently that had me question where to handle state. I built a global store using pinia(vue) and it all worked perfectly. Until someone asked me to pin reactive data on the mac tray. The data is stored “too far forward” as sending updates to the tray requires calling back to electrons main process, then redirecting data to tray. Not difficult, but suboptimal spaghetti. This had me realize that it makes more sense to store reactive state in the main process, so data only has to move "forward". ...

Error on _app.tsx types using react query

on the latest version of nextjs i get this error ```ts type NextPageWithLayout = NextPage & { Layout?: React.ElementType authenticate?: boolean...

zod array still required?

Somehow following in my zod schema still requires my field
tags: z.string().array().nullish(),
tags: z.string().array().nullish(),
...

Cross platform stack (web & mobile)

Do you folks have any recommendations on what an optimal stack from a developer point of view would be for a cross platform app (web & mobile) with backend included and full type safety? Technologies/libs I have been considering to use but I'd gladly take other suggestions. FE Related:...

Initialized Project, just seeking clarification on next steps

I've just spun up a t3 app. It defaults to sqlite but I want to use postgres. So, I've spun up a postgres docker container and changed the .env database URL. Other than uncommenting the annotations in the prisma schema, is there anything else I need to do to migrate to the new DB properly so I can start building out my data model?...

Better-uptime or an alternative?

curious to what people are using to monitor their apps we have many running projects different langs/frameworks and by proxy many ec2 instances we also have internal servers so not everything is publily acessable but still want to monitor uptime on it...

ts types dumb question

dumb question, what's the difference between
{input}:{input:string} Or input:string
{input}:{input:string} Or input:string
in a jsx.element passed as prop for example...

Multi-tenant - easy no?

Am I missing something in plain sight ? Is there a well trodden path / mature framework within typical Next.js Prisma Vercel stacks for implementing a solid multi-tenanted SaaS ? Or is it that everyone rolls their own.