Closed ghost closed 2 weeks ago
I'm not sure why TypeScript does not infer the CustomEdge
correctly, but here is some pointers:
null
as a third argument is not valid, if you dont want to pass any pagination arguments, you need to use {}
Record
(that is returned from findMany
) yourself: https://github.com/devoxa/prisma-relay-cursor-connection/blob/master/src/index.ts#L12-L17I'm not sure why TypeScript does not infer the
CustomEdge
correctly, but here is some pointers:
null
as a third argument is not valid, if you dont want to pass any pagination arguments, you need to use{}
- You can pass the generics manually but you will have to also type the
Record
(that is returned fromfindMany
) yourself: https://github.com/devoxa/prisma-relay-cursor-connection/blob/master/src/index.ts#L12-L17
{}
was my first approach but null was for testing if it changes anything in typing, it doesn'tconst fn = <K extends Object<T>, T extends { id: string }>(cb: () => T[], { cb }: { cb: () => K ) => {}
maybe this typing would be more "developer friendly"?
I use
prisma-relay-cursor-connection
with my NestJS backend, I created a functionThe problem is I get an error in
recordToEdge
function where I add thumbnail that is a media of the last updated relationstory
. The error saysError disappears when I return the list of
stories
inrecordToEdge
function, but I don't want to do it, I can also fix that passing<any, StoryCategory>
as an TS argument tofindManyCursorConnection
but I don't want to useany
and Prisma doesn't generate relations as types in e.g.StoryCategory
type from prisma schema so I can't pass PrismaStoryCategory as argument instead of any because generic function doesn't see relation and I don't want to create more types than I mustIt would be lovely if I could pass type I want as a first argument in
findManyCursorConnection
or pass it anywhere it would be possible to strictly type my edge typebtw. this problem is weird because I also did it in another function
And I don't return gamesOnCountries relation and typescript doesn't scream about it's not present in returned object
Another thing I spotted is that when I use
recordToEdge
function, type returned fromfindManyCursorConnection
doesn't modify type returned as node, it's still a type returned from prisma query