How can i make the list returned by findMany to us...
# orm-help
h
How can i make the list returned by findMany to use the proper type?
Copy code
const [mapCount, mapList] = await prisma.$transaction([
            prisma.user.count(),
            prisma.map.findMany()
]);
r
Cannot reproduce your type issue unfortunately. I’m on the latest version of Prisma.
h
Problem only appers when making multiple queries, inside the tranasction.
Think the problem is that i use a select statement, is there any way to make it return any type instead of {}?
@Ryan Is it possible to use transaction here?
r
Can you share the schema and select? The types are always correctly mapped even if you use a transaction
h
The problem is that my select is a object that is built dynamically and inserted into the query.
So that is any type, which resulted in the {} type so doing the following seems to solve it:
Copy code
const [count, entries] = await prisma.$transaction([
            prisma.map.count(),
            prisma.map.findMany({
                where: where,
                select: select,
                skip: Number(json.start_index),
                take: Number(json.max_result)
            }) as any
        ]);
Note the "as any" 😞
:-)*
r
Why are you using
as any
?
h
Because of select it does not set the Map type
«As any» fixes that
r
select
is dynamically added?
h
Yeah it is built before calling that, can i type that somehow?
r
Unfortunately not, dynamically typing
select
based on user input is not possible directly.
h
Ok, is ther any way i can do it conditionally based on if a variable is present?
r
Selecting specific values or the entire
select
?