Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type augmentation of RequestContext #9035

Merged
merged 1 commit into from
Nov 5, 2024

Conversation

r1tsuu
Copy link
Member

@r1tsuu r1tsuu commented Nov 5, 2024

What?

Makes this to actually work

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
    // ...
  }
}
image

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

@r1tsuu r1tsuu merged commit f52b7c4 into beta Nov 5, 2024
57 checks passed
@r1tsuu r1tsuu deleted the fix/type-augmentation-typescript branch November 5, 2024 21:14
Copy link

github-actions bot commented Nov 6, 2024

🚀 This is included in version v3.0.0-beta.125

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type Augmentation does not work
2 participants