I’m still dealing with solving an issue that is really important for my project to progress.
I’m not sure if I’m doing something wrong, or there’s an bug.
I’m trying to findMany & populate. The issue I have is the types are wrongly assinged.
const collections = await strapi.entityService.findMany("api::device-collection.device-collection", {
populate: {
devices: {
populate: {
stores: true,
expertScore: true,
images: true,
specification: true
}
}
}
});
const collections: ContentType<"api::device-collection.device-collection", Schema.NonPopulatableAttributeNames<"api::device-collection.device-collection">>[]
That’s the type I’m getting. Data inside request is populated correctly but the type is totaly wrong.
This topic has been created from a Discord post (1290781593946030100) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord
Also, are there any docs for Typescipt types? Cause all I currently do is reverse engineer the whole source code for a manual typing with populate
I would suggest you use as
temporary, not sure about v5 but in v4 these major types had depth around 3 or 4 levels
same issue, I cannot use the strapi.documents
document service with filter or fields, since strapi fails to boot, due to some typescript errors…
ive resorted back to using the query engine api
You’d prolly also should go with as
since likely this is going to be fixed at some point
And query engine good only for fetching from database…
doing this now
const user_info = await strapi.db.query(API_USER_INFO).create({
data: {
height: 0,
user: {
// db.query uses the actual id, not the document id
connect: [userId]
}
}
});
and doint the filtering in js …
const user_infos: any = await strapi.documents(API_USER_INFO).findMany({
populate: '*',
});
// only return my user_infos, this should be doable directly via findMany and filters
const filtered_user_info = user_infos.filter((user_info: any) => user_info.user.id === ctx.state.user.id);
which is not ideal, the database should do this 
Well for the second part it should be something like:
const userInfos = await strapi.db.query.findMany({ where: { user: { id: userId } }, populate: … })
For the first part, I’ve would recommend using document service (since entity creation isn’t something you want db query for)
but isnt the documentService supposed to be “used” and with working filtering?
I was not able to get the documentService to work with create. It always throws some typescript errors. db.query works fine.
this filtering works
const user_infos = await strapi.db.query(API_USER_INFO).findMany({
where: {
user: {id: ctx.state.user.id}
}, populate: ['user']
})
however, its still the db query engine 
ok, but with the as typecast, this seems to also work
const user_infos = await strapi.documents(API_USER_INFO).findMany({
where: {
user: {id: ctx.state.user.id}
}, populate: 'user' as Populate.Any<ContentType>
})
doesnt however work for the documents.create api
Just put as any
after weight)
Or @ts-ignore
before, ignores are easier to find after they fix the issue