Reusable Component to take router as props / dependency injection. How to type?
for example:
Content is either movies or series.
I have movieRouter and seriesRouter with the same procedures.
How can i type api ?
22 Replies
This leads me back to this.
https://discord.com/channels/867764511159091230/867764511159091233/1204442193230831646
You linked to the blog post I wrote on this right? The answer is the second half to that
If you have any more specific questions I can try to help but this is a broad one
Hi @Nick Lucas Thanks for responding. I am not sure how to solve this type issue.
If you can put together a stackblitz example then I could take a look. It’s typescript foo though so if you don’t understand the solution then you’re going to be in trouble down the line
Should be possible anyway
hm, i use typescript and have for a couple of years, but if its messy for the sake of readability i might need another solution.
I was trying to create a reuseable
createService
Yeah I have several of these at work, we have about 25 generated routers. It’s a good pattern once you crack the generics stuff
i can put together a stackblitz no problem
I don’t use Prisma though so I’d need to have a play with a dummy version 😇
yeah i was trying to find some base Prisma delegate verison
const prismaModel: Prisma.MovieDelegate<DefaultArgs> | Prisma.SerieDelegate<DefaultArgs> | Prisma.UserDelegate<DefaultArgs>
to extend from but cannot find anythingSometimes you have to F12 into the declarations and really understand what to use that way
Prisma must have some common type you can extend from
thats what i was hoping for but cant find it
but im very rusty with TS too, had a year off. maybe you can see.
What about “keyof prisma”
If you get the model by key then having a generic key is likely enough to calculate your return type and get the concrete model
does this work?
https://stackblitz.com/~/github.com/lwears/ReelScore
checking this
hm no i need to fix the stackblitz
hm, seems prisma cannot run in a webcontainer / stackblitz
That’s usually okay, we’re looking at types anyway
Afraid I’m at work without access for now though so I’ll need to check it out later tonight