Skip to content

Commit f52b7c4

Browse files
authored
fix: type augmentation of RequestContext (#9035)
### What? Makes this to actually work ```ts import type { RequestContext as OriginalRequestContext } from 'payload' declare module 'payload' { // Create a new interface that merges your additional fields with the original one export interface RequestContext extends OriginalRequestContext { myObject?: string // ... } } ``` <img width="502" alt="image" src="https://github.com/user-attachments/assets/38570d3c-e8a8-48aa-a57d-6d11e79394f5"> ### Why? This is described in our docs https://payloadcms.com/docs/beta/hooks/context#typescript therefore it should work. ### How? In order to get the declaration work, we need to reuse the type from the root file `payload/src/index.js`. Additionally, removes `RequestContext` type duplication in both `payload/src/types/index.js` and `payload/src/index.js`. Fixes #8851
1 parent 2eeed4a commit f52b7c4

File tree

32 files changed

+76
-69
lines changed

32 files changed

+76
-69
lines changed

packages/payload/src/admin/RichText.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import type {
1212
Validate,
1313
} from '../fields/config/types.js'
1414
import type { SanitizedGlobalConfig } from '../globals/config/types.js'
15-
import type { JsonObject, Payload, PayloadRequest, RequestContext } from '../types/index.js'
15+
import type { RequestContext } from '../index.js'
16+
import type { JsonObject, Payload, PayloadRequest } from '../types/index.js'
1617
import type { RichTextFieldClientProps } from './fields/RichText.js'
1718
import type { CreateMappedComponent } from './types.js'
1819

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ import type { Field, JoinField, RelationshipField, UploadField } from '../../fie
3535
import type {
3636
CollectionSlug,
3737
JsonObject,
38+
RequestContext,
3839
TypedAuthOperations,
3940
TypedCollection,
4041
TypedCollectionSelect,
4142
} from '../../index.js'
4243
import type {
4344
PayloadRequest,
44-
RequestContext,
4545
SelectType,
4646
Sort,
4747
TransformCollectionWithSelect,

packages/payload/src/collections/operations/local/count.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js'
2-
import type { Document, PayloadRequest, RequestContext, Where } from '../../../types/index.js'
1+
import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'
2+
import type { Document, PayloadRequest, Where } from '../../../types/index.js'
33

44
import { APIError } from '../../../errors/index.js'
55
import { createLocalReq } from '../../../utilities/createLocalReq.js'

packages/payload/src/collections/operations/local/create.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js'
1+
import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'
22
import type {
33
Document,
44
PayloadRequest,
5-
RequestContext,
65
SelectType,
76
TransformCollectionWithSelect,
87
} from '../../../types/index.js'

packages/payload/src/collections/operations/local/delete.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js'
1+
import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'
22
import type {
33
Document,
44
PayloadRequest,
5-
RequestContext,
65
SelectType,
76
TransformCollectionWithSelect,
87
Where,

packages/payload/src/collections/operations/local/duplicate.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import type { CollectionSlug, TypedLocale } from '../../..//index.js'
2-
import type { Payload } from '../../../index.js'
2+
import type { Payload, RequestContext } from '../../../index.js'
33
import type {
44
Document,
55
PayloadRequest,
6-
RequestContext,
76
SelectType,
87
TransformCollectionWithSelect,
98
} from '../../../types/index.js'
10-
import type { DataFromCollectionSlug, SelectFromCollectionSlug } from '../../config/types.js'
9+
import type { SelectFromCollectionSlug } from '../../config/types.js'
1110

1211
import { APIError } from '../../../errors/index.js'
1312
import { createLocalReq } from '../../../utilities/createLocalReq.js'

packages/payload/src/collections/operations/local/find.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import type { PaginatedDocs } from '../../../database/types.js'
2-
import type { CollectionSlug, JoinQuery, Payload, TypedLocale } from '../../../index.js'
2+
import type {
3+
CollectionSlug,
4+
JoinQuery,
5+
Payload,
6+
RequestContext,
7+
TypedLocale,
8+
} from '../../../index.js'
39
import type {
410
Document,
511
PayloadRequest,
6-
RequestContext,
712
SelectType,
813
Sort,
914
TransformCollectionWithSelect,

packages/payload/src/collections/operations/local/findByID.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
/* eslint-disable no-restricted-exports */
2-
import type { CollectionSlug, JoinQuery, Payload, SelectType, TypedLocale } from '../../../index.js'
2+
import type {
3+
CollectionSlug,
4+
JoinQuery,
5+
Payload,
6+
RequestContext,
7+
SelectType,
8+
TypedLocale,
9+
} from '../../../index.js'
310
import type {
411
ApplyDisableErrors,
512
Document,
613
PayloadRequest,
7-
RequestContext,
814
TransformCollectionWithSelect,
915
} from '../../../types/index.js'
1016
import type { SelectFromCollectionSlug } from '../../config/types.js'

packages/payload/src/collections/operations/local/findVersionByID.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js'
2-
import type { Document, PayloadRequest, RequestContext, SelectType } from '../../../types/index.js'
1+
import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'
2+
import type { Document, PayloadRequest, SelectType } from '../../../types/index.js'
33
import type { TypeWithVersion } from '../../../versions/types.js'
44
import type { DataFromCollectionSlug } from '../../config/types.js'
55

packages/payload/src/collections/operations/local/findVersions.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import type { PaginatedDocs } from '../../../database/types.js'
2-
import type { CollectionSlug, Payload, TypedLocale } from '../../../index.js'
3-
import type {
4-
Document,
5-
PayloadRequest,
6-
RequestContext,
7-
SelectType,
8-
Sort,
9-
Where,
10-
} from '../../../types/index.js'
2+
import type { CollectionSlug, Payload, RequestContext, TypedLocale } from '../../../index.js'
3+
import type { Document, PayloadRequest, SelectType, Sort, Where } from '../../../types/index.js'
114
import type { TypeWithVersion } from '../../../versions/types.js'
125
import type { DataFromCollectionSlug } from '../../config/types.js'
136

0 commit comments

Comments
 (0)