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

Type Augmentation does not work #8851

Open
akantic opened this issue Oct 24, 2024 · 0 comments
Open

Type Augmentation does not work #8851

akantic opened this issue Oct 24, 2024 · 0 comments
Labels
status: needs-triage Possible bug which hasn't been reproduced yet v3

Comments

@akantic
Copy link

akantic commented Oct 24, 2024

Describe the Bug

https://payloadcms.com/docs/beta/hooks/context#typescript

This does not seem to work for me in version 3 beta-117. It keeps using the old type, however if I cast the type directly then it works, but the original type is not extended but replaced instead.

import { RequestContext } from 'payload'

...
    read: (args) => {
      let contextFromArgs = args.req.context;
      contextFromArgs.myObject; // does not recognize myObject

      let explicitContext: RequestContext; 
      explicitContext.myObject; // works but the type is completely replaced, not augmented
    },
...

Link to the code that reproduces this issue

https://github.com/payloadcms/payload/tree/beta/examples/multi-tenant

Reproduction Steps

To reproduce, I used multi-tenant example from the beta branch.

Create a file types.d.ts in the root directory with the content described in the official docs, and try to access the context from any hook using args.req.context.myObject.

Which area(s) are affected? (Select all that apply)

area: core

Environment Info

Binaries:
Node: 20.11.0
npm: 10.2.4
Yarn: 1.22.19
pnpm: 9.12.2
Relevant Packages:
payload: 3.0.0-beta.112
next: 15.0.0-canary.173
@payloadcms/db-mongodb: 3.0.0-beta.112
@payloadcms/graphql: 3.0.0-beta.112
@payloadcms/next/utilities: 3.0.0-beta.112
@payloadcms/richtext-lexical: 3.0.0-beta.112
@payloadcms/translations: 3.0.0-beta.112
@payloadcms/ui/shared: 3.0.0-beta.112
react: 19.0.0-rc-3edc000d-20240926

@akantic akantic added status: needs-triage Possible bug which hasn't been reproduced yet v3 labels Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs-triage Possible bug which hasn't been reproduced yet v3
Projects
None yet
Development

No branches or pull requests

1 participant