Skip to content

Commit

Permalink
fix: invalid payload.collections type (#9414)
Browse files Browse the repository at this point in the history
### What?
`payload.collections` was improperly typed.
This doesn't seem to work: (the type is `{}`)
```
collections: {
  [slug: CollectionSlug]: Collection
} = {}
```
<img width="794" alt="image"
src="https://github.com/user-attachments/assets/7daceab9-8f43-433b-9201-1bf8c48fb8ca">

However, this does:
```ts
collections: Record<CollectionSlug, Collection> = {}
```
<img width="540" alt="image"
src="https://github.com/user-attachments/assets/e37d595d-f5b4-4b02-b190-bb5d4063787d">


Additionally, the same fix applied to `Permissions`,
`PolymorphicUploadField['admin']['sortOptions']`,
`PolymorphicRelationshipField['admin']['sortOptions']`
  • Loading branch information
r1tsuu authored Nov 21, 2024
1 parent f5683b0 commit 91dcf6d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
8 changes: 2 additions & 6 deletions packages/payload/src/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,8 @@ export type SanitizedDocumentPermissions = SanitizedCollectionPermission | Sanit

export type Permissions = {
canAccessAdmin: boolean
collections?: {
[collectionSlug: CollectionSlug]: CollectionPermission
}
globals?: {
[globalSlug: GlobalSlug]: GlobalPermission
}
collections?: Record<CollectionSlug, CollectionPermission>
globals?: Record<GlobalSlug, GlobalPermission>
}

export type SanitizedPermissions = {
Expand Down
4 changes: 2 additions & 2 deletions packages/payload/src/fields/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ type UploadAdminClient = AdminClient & Pick<UploadAdmin, 'allowCreate' | 'isSort

export type PolymorphicUploadField = {
admin?: {
sortOptions?: { [collectionSlug: CollectionSlug]: string }
sortOptions?: Partial<Record<CollectionSlug, string>>
} & UploadAdmin
relationTo: CollectionSlug[]
} & SharedUploadProperties
Expand Down Expand Up @@ -1044,7 +1044,7 @@ type RelationshipAdminClient = AdminClient &

export type PolymorphicRelationshipField = {
admin?: {
sortOptions?: { [collectionSlug: CollectionSlug]: string }
sortOptions?: Partial<Record<CollectionSlug, string>>
} & RelationshipAdmin
relationTo: CollectionSlug[]
} & SharedRelationshipProperties
Expand Down
4 changes: 1 addition & 3 deletions packages/payload/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ export class BasePayload {

authStrategies: AuthStrategy[]

collections: {
[slug: CollectionSlug]: Collection
} = {}
collections: Record<CollectionSlug, Collection> = {}

config: SanitizedConfig
/**
Expand Down

0 comments on commit 91dcf6d

Please sign in to comment.