payloadcms / payload

The best way to build a modern backend + admin UI. No black magic, all TypeScript, and fully open-source, Payload is both an app framework and a headless CMS.
https://payloadcms.com
MIT License
21.1k stars 1.27k forks source link

Type collision with generated types #6958

Closed bajzarpa closed 2 days ago

bajzarpa commented 6 days ago

Link to reproduction

No response

Describe the Bug

The payload-types.ts exports an interface like this:

export interface GeneratedTypes extends Config {}

but the node_modules/payload/dist/index.d.ts also declares a GeneratedTypes which collides with the GeneratedTypes above.

Sometimes the ts uses the payload-types.ts other times it uses node_modules/payload/dist/index.d.ts

And this what cause the TypeWithID & Record<string, unknown> errors when using local api.

To Reproduce

Its random, sometimes one GeneratedTypes has been referenced instead of the other

Payload Version

2.22.2

Adapters and Plugins

No response

neslob commented 5 days ago

--- 2024-06-28 UPDATE ---

This happens on 3.0.0-beta.53 for me.


Getting the same error.

No idea, where this came from. Sadly I did not throughly committed while testing.

For me, even pnpm run dev broke. But, I without turbo, it works.

    "start": "next dev",
    "dev": "next dev --turbo",

Breaking production builds could be solved by removing/commenting the generate code


// declare module 'payload' {
//   export interface GeneratedTypes extends Config {}
// }
AlessioGr commented 5 days ago

Are you on TypeScript 5.5 or 5.4? If you are on TypeScript 5.5, can you check if this issue still appears on 5.4? (We do not support TypeScript 5.5 on 2.0)

neslob commented 5 days ago

Oh! sorry, I have missed details (added above).

For me, it is happening on 3.0.0-beta.53. Yes, it happens on TypeScript 5.5. But downgrading, did not solve it.

I am happy to open a separate issue.

bajzarpa commented 5 days ago

Are you on TypeScript 5.5 or 5.4? If you are on TypeScript 5.5, can you check if this issue still appears on 5.4? (We do not support TypeScript 5.5 on 2.0)

Downgrading TS to 5.4 fixed this issue indeed. Thank you @AlessioGr

carstenblt commented 5 days ago

Oh! sorry, I have missed details (added above).

For me, it is happening on 3.0.0-beta.53. Yes, it happens on TypeScript 5.5. But downgrading, did not solve it.

I am happy to open a separate issue.

Check if ts is really downgraded. If you use ^5.4.5, pnpm will still install/keep 5.5.

Had the same problem, keeping 5.4.5 worked.

paulpopus commented 2 days ago

Closing, we will support ts 5.5 on 3.0 but 2.0 will be compatible with 5.4.5 only.