Skip to content

Commit 339a0c3

Browse files
authored
fix: use TSiblingData for previousSiblingDoc in FieldHook (#14503)
### What? In field hooks, `previousSiblingDoc` is typed as `TData`. ### Why? This value should actually be typed as `TSiblingData`, I've confirmed the sibling data is actually what is returned when a field hook runs. ### How? Updated `FieldHook` typing, as well as `RichText` field hook typings Fixes #9735
1 parent 3c9f56e commit 339a0c3

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

packages/payload/src/admin/RichText.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,38 +57,37 @@ export type AfterReadRichTextHookArgs<
5757
export type AfterChangeRichTextHookArgs<
5858
TData extends TypeWithID = any,
5959
TValue = any,
60-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6160
TSiblingData = any,
6261
> = {
6362
/** A string relating to which operation the field type is currently executing within. */
6463
operation: 'create' | 'update'
6564
/** The document before changes were applied. */
6665
previousDoc?: TData
6766
/** The sibling data of the document before changes being applied. */
68-
previousSiblingDoc?: TData
67+
previousSiblingDoc?: TSiblingData
6968
/** The previous value of the field, before changes */
7069
previousValue?: TValue
7170
}
7271

7372
export type BeforeValidateRichTextHookArgs<
73+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
7474
TData extends TypeWithID = any,
7575
TValue = any,
76-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
7776
TSiblingData = any,
7877
> = {
7978
/** A string relating to which operation the field type is currently executing within. */
8079
operation: 'create' | 'update'
8180
overrideAccess?: boolean
8281
/** The sibling data of the document before changes being applied. */
83-
previousSiblingDoc?: TData
82+
previousSiblingDoc?: TSiblingData
8483
/** The previous value of the field, before changes */
8584
previousValue?: TValue
8685
}
8786

8887
export type BeforeChangeRichTextHookArgs<
88+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8989
TData extends TypeWithID = any,
9090
TValue = any,
91-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
9291
TSiblingData = any,
9392
> = {
9493
/**
@@ -111,7 +110,7 @@ export type BeforeChangeRichTextHookArgs<
111110
operation?: 'create' | 'delete' | 'read' | 'update'
112111
overrideAccess: boolean
113112
/** The sibling data of the document before changes being applied. */
114-
previousSiblingDoc?: TData
113+
previousSiblingDoc?: TSiblingData
115114
/** The previous value of the field, before changes */
116115
previousValue?: TValue
117116
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export type FieldHookArgs<TData extends TypeWithID = any, TValue = any, TSibling
201201
/** The document before changes were applied, only in `afterChange` hooks. */
202202
previousDoc?: TData
203203
/** The sibling data of the document before changes being applied, only in `beforeChange`, `beforeValidate`, `beforeDuplicate` and `afterChange` field hooks. */
204-
previousSiblingDoc?: TData
204+
previousSiblingDoc?: TSiblingData
205205
/** The previous value of the field, before changes, only in `beforeChange`, `afterChange`, `beforeDuplicate` and `beforeValidate` field hooks. */
206206
previousValue?: TValue
207207
/** The Express request object. It is mocked for Local API operations. */

0 commit comments

Comments
 (0)