Im getting '(TypeWithID & Record<string, unknown>)[]' from local payload api instead of one from generated types.
// app/(app)/page.tsx
...
import { getPayload } from 'payload';
import configPromise from '@payload-config';
import { type News } from '~~/payload-types';
const getArticles = async () => {
const payload = await getPayload({
config: configPromise,
});
const newsCollection: News[] = await payload
.find({
collection: 'news',
sort: '-createdAt',
})
.then((res) => res.docs.filter((doc) => doc._status === 'published'));
return newsCollection;
};
...How can i get desired type or convert it?
payload
.find<'news'>({
collection: 'news',
sort: '-createdAt',
})Still getting same type
I think it's because of this
.then((res) => res.docs.filter((doc) => doc._status === 'published'));do this after the query. in another variable
same
you can put this (
doc._status === 'published') in the where query btw. and if you want all the news without limit, you have to pass
pagination: falsetry passing empty
whereempty?
where: {},
are you using latest version of payload 3?
yes, beta.47
what is your file extension type.
is it
.tsor
.jsnvm
.tsx
.47, this is working good in my case
Can you share your tsconfig?
and typescript version
weird
Ok, it turns out that this is problem only with vscode. I opened project in webstorm and it returns correct type
And thanks for your help
I am experiencing the same issue on vs code and tried payload versions beta.40 and beta.53.
No luck.
Any ideas?
Got the same error this morning updating to TypeScript 5.5. The root cause seem to be a Duplicate identifier error in the Payload generated types. I've reported it in the core-dev channel. If you go back to TS 5.4 it should be OK.
I've rollbacked to TS 5.4.5 without any luck..
const providerConfig = await payload.findGlobal({
slug: "auth",
depth: 2,
}) as unknown as Auth;I'm doing this as alternative for now. LMK if you guys got better fix
looks like fixed in beta.
read the discussion here
I've the same problem after updating VsCode, but with payload version 2. Anyone know how to fix this?
Star
Discord
online
Get dedicated engineering support directly from the Payload team.