Skip to content

Commit 850c252

Browse files
authored
feat: add augmentable interfaces for collection and global custom properties (#14729)
### What? Adds augmentable interfaces for the `custom` property on collections and globals: - `CollectionCustom` - `CollectionAdminCustom` - `GlobalCustom` - `GlobalAdminCustom` Also updates `plugin-import-export` to use `CollectionAdminCustom` for its internal storage. ### Why? Fields already have `FieldCustom` which plugins can augment for type-safe custom config. Collections and globals were still using `Record<string, any>` directly, so there was no way to get proper types when building plugins that need collection/global-level configuration. This made it annoying to build well-typed plugins since you'd lose all type safety and autocomplete at the collection/global level. ### How? - Added the four interfaces (same pattern as `FieldCustom` - empty interfaces extending `Record<string, any>`) - Updated the type definitions in `collections/config/types.ts` and `globals/config/types.ts` to use them - Updated `plugin-import-export` to augment `CollectionAdminCustom` so it gets proper types for the `disabledFields` array it stores Fixes #14724
1 parent 32560e9 commit 850c252

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

packages/payload/src/collections/config/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import type {
3535
} from '../../fields/config/types.js'
3636
import type { CollectionFoldersConfiguration } from '../../folders/types.js'
3737
import type {
38+
CollectionAdminCustom,
39+
CollectionCustom,
3840
CollectionSlug,
3941
JsonObject,
4042
RequestContext,
@@ -383,7 +385,7 @@ export type CollectionAdminOptions = {
383385
}
384386
}
385387
/** Extension point to add your custom data. Available in server and client. */
386-
custom?: Record<string, any>
388+
custom?: CollectionAdminCustom
387389
/**
388390
* Default columns to show in list view
389391
*/
@@ -506,7 +508,7 @@ export type CollectionConfig<TSlug extends CollectionSlug = any> = {
506508
*/
507509
auth?: boolean | IncomingAuthType
508510
/** Extension point to add your custom data. Server only. */
509-
custom?: Record<string, any>
511+
custom?: CollectionCustom
510512
/**
511513
* Used to override the default naming of the database table or collection with your using a function or string
512514
* @WARNING: If you change this property with existing data, you will need to handle the renaming of the table in your database or by using migrations

packages/payload/src/globals/config/types.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ import type {
2323
} from '../../config/types.js'
2424
import type { DBIdentifierName } from '../../database/types.js'
2525
import type { Field, FlattenedField } from '../../fields/config/types.js'
26-
import type { GlobalSlug, RequestContext, TypedGlobal, TypedGlobalSelect } from '../../index.js'
26+
import type {
27+
GlobalAdminCustom,
28+
GlobalCustom,
29+
GlobalSlug,
30+
RequestContext,
31+
TypedGlobal,
32+
TypedGlobalSelect,
33+
} from '../../index.js'
2734
import type { PayloadRequest, SelectIncludeType, Where } from '../../types/index.js'
2835
import type { IncomingGlobalVersions, SanitizedGlobalVersions } from '../../versions/types.js'
2936

@@ -134,7 +141,7 @@ export type GlobalAdminOptions = {
134141
}
135142
}
136143
/** Extension point to add your custom data. Available in server and client. */
137-
custom?: Record<string, any>
144+
custom?: GlobalAdminCustom
138145
/**
139146
* Custom description for collection
140147
*/
@@ -179,7 +186,7 @@ export type GlobalConfig<TSlug extends GlobalSlug = any> = {
179186
}
180187
admin?: GlobalAdminOptions
181188
/** Extension point to add your custom data. Server only. */
182-
custom?: Record<string, any>
189+
custom?: GlobalCustom
183190
/**
184191
* Customize the SQL table name
185192
*/

packages/payload/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,14 @@ export {
14591459

14601460
export interface FieldCustom extends Record<string, any> {}
14611461

1462+
export interface CollectionCustom extends Record<string, any> {}
1463+
1464+
export interface CollectionAdminCustom extends Record<string, any> {}
1465+
1466+
export interface GlobalCustom extends Record<string, any> {}
1467+
1468+
export interface GlobalAdminCustom extends Record<string, any> {}
1469+
14621470
export { sanitizeFields } from './fields/config/sanitize.js'
14631471

14641472
export type {

packages/plugin-import-export/src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ declare module 'payload' {
212212
'plugin-import-export'?: {
213213
/**
214214
* When `true` the field is **completely excluded** from the import-export plugin:
215-
* - It will not appear in the Fields to export selector.
215+
* - It will not appear in the "Fields to export" selector.
216216
* - It is hidden from the preview list when no specific fields are chosen.
217217
* - Its data is omitted from the final CSV / JSON export.
218218
* @default false
@@ -224,4 +224,14 @@ declare module 'payload' {
224224
toCSV?: ToCSVFunction
225225
}
226226
}
227+
228+
export interface CollectionAdminCustom {
229+
'plugin-import-export'?: {
230+
/**
231+
* Array of field paths that are disabled for import/export.
232+
* These paths are collected from fields marked with `custom['plugin-import-export'].disabled = true`.
233+
*/
234+
disabledFields?: string[]
235+
}
236+
}
227237
}

0 commit comments

Comments
 (0)