From 91dcf6dc08126c71f937655080098f2964ad7407 Mon Sep 17 00:00:00 2001
From: Sasha <64744993+r1tsuu@users.noreply.github.com>
Date: Thu, 21 Nov 2024 22:58:04 +0200
Subject: [PATCH] fix: invalid `payload.collections` type (#9414)
### What?
`payload.collections` was improperly typed.
This doesn't seem to work: (the type is `{}`)
```
collections: {
[slug: CollectionSlug]: Collection
} = {}
```
However, this does:
```ts
collections: Record = {}
```
Additionally, the same fix applied to `Permissions`,
`PolymorphicUploadField['admin']['sortOptions']`,
`PolymorphicRelationshipField['admin']['sortOptions']`
---
packages/payload/src/auth/types.ts | 8 ++------
packages/payload/src/fields/config/types.ts | 4 ++--
packages/payload/src/index.ts | 4 +---
3 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/packages/payload/src/auth/types.ts b/packages/payload/src/auth/types.ts
index 371261c682..e51ee42cfd 100644
--- a/packages/payload/src/auth/types.ts
+++ b/packages/payload/src/auth/types.ts
@@ -100,12 +100,8 @@ export type SanitizedDocumentPermissions = SanitizedCollectionPermission | Sanit
export type Permissions = {
canAccessAdmin: boolean
- collections?: {
- [collectionSlug: CollectionSlug]: CollectionPermission
- }
- globals?: {
- [globalSlug: GlobalSlug]: GlobalPermission
- }
+ collections?: Record
+ globals?: Record
}
export type SanitizedPermissions = {
diff --git a/packages/payload/src/fields/config/types.ts b/packages/payload/src/fields/config/types.ts
index 588dece10d..963d329451 100644
--- a/packages/payload/src/fields/config/types.ts
+++ b/packages/payload/src/fields/config/types.ts
@@ -863,7 +863,7 @@ type UploadAdminClient = AdminClient & Pick>
} & UploadAdmin
relationTo: CollectionSlug[]
} & SharedUploadProperties
@@ -1044,7 +1044,7 @@ type RelationshipAdminClient = AdminClient &
export type PolymorphicRelationshipField = {
admin?: {
- sortOptions?: { [collectionSlug: CollectionSlug]: string }
+ sortOptions?: Partial>
} & RelationshipAdmin
relationTo: CollectionSlug[]
} & SharedRelationshipProperties
diff --git a/packages/payload/src/index.ts b/packages/payload/src/index.ts
index e0a3f5b9ae..94a1bcdb0c 100644
--- a/packages/payload/src/index.ts
+++ b/packages/payload/src/index.ts
@@ -242,9 +242,7 @@ export class BasePayload {
authStrategies: AuthStrategy[]
- collections: {
- [slug: CollectionSlug]: Collection
- } = {}
+ collections: Record = {}
config: SanitizedConfig
/**