payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
23.13k stars 1.44k forks source link

PaginatedDocs<TypeWithID & Record<string, unknown>> #6799

Closed szpolny closed 2 months ago

szpolny commented 2 months ago

Payload Version

3.0.0-beta.47

Node Version

v22.3.0

Next.js Version

15.0.0-rc.0

Describe the Bug

// 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 = await payload.find<'news'>({
    collection: 'news',
    sort: '-createdAt',
    pagination: false,
    where: {
      _status: {
        equals: 'published',
      },
    },
  });

  return newsCollection;
};

...

In this code im quering 'news' collection from local api. Property docs, inside response object should be Type from generated:types but it is not.

Adapters and Plugins

db-postgres, storage-uploadthing, richtext-lexical

szpolny commented 2 months ago

Ok, it turns out that this is problem with vscode. I opened project in webstorm and it returns correct type.

ydemetriades commented 2 months ago

I am experiencing the same issue (VS Code).

Tried it on beta.40 and beta.53

Girbi commented 2 months ago

Same issue, payload version: 2.0.0, VS Code. Typescript version 5.5.3 is not working.

RyanScarbrough commented 1 month ago

Same issue, woke up today and suddenly had it.

Payload version 2.22.0 VS Code version 1.91.1

const { docs: orders } = await payload.find({
     collection: "orders",
     where: {
          id: {
               equals: orderId,
          },
     },
});

orders is now of type: (TypeWithID & Record<string, unknown>)[]

RyanScarbrough commented 1 month ago

I believe this is due to a Duplicate identifier 'GeneratedTypes' in payload-types.ts

Issues: https://github.com/payloadcms/payload/issues/6958 https://github.com/payloadcms/payload/issues/6896

This appears to be a VS Code problem, as WebStorm doesn't have this problem.

Using TypeScript version 5.4.5 did not fix the issue for me.

AlessioGr commented 1 month ago

I believe this is due to a Duplicate identifier 'GeneratedTypes' in payload-types.ts

Issues: #6958 #6896

This appears to be a VS Code problem, as WebStorm doesn't have this problem.

Using TypeScript version 5.4.5 did not fix the issue for me.

VC Code by default often uses an incorrect typescript version. You will have to set it to the workspace typescript version (5.4.5): https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-the-workspace-version-of-typescript

RyanScarbrough commented 1 month ago

I believe this is due to a Duplicate identifier 'GeneratedTypes' in payload-types.ts Issues: #6958 #6896 This appears to be a VS Code problem, as WebStorm doesn't have this problem. Using TypeScript version 5.4.5 did not fix the issue for me.

VC Code by default often uses an incorrect typescript version. You will have to set it to the workspace typescript version (5.4.5): https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-the-workspace-version-of-typescript

Yup this fixed the issue for me, thank you! For whatever reason VS Code decided to switch to an incompatible version of TypeScript. Switching back to the workspace version fixed it just as you said.

ts-fix

toximate commented 3 weeks ago

Same issue and yet no solutions , payload@2.25.0 & typescript@5.5.4

AlessioGr commented 3 weeks ago

Same issue and yet no solutions , payload@2.25.0 & typescript@5.5.4

Payload v2 does not and will never support TypeScript 5.5+. Please switch to TypeScript 5.4.5

toximate commented 3 weeks ago

Same issue and yet no solutions , payload@2.25.0 & typescript@5.5.4

Payload v2 does not and will never support TypeScript 5.5+. Please switch to TypeScript 5.4.5

Thank you

github-actions[bot] commented 1 day ago

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.