Skip to content

fix(cloudflare): Account for static fields in wrapper type #16303

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

Merged
merged 1 commit into from
May 15, 2025

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented May 15, 2025

fixes #16247

By adjusting the generic, we'll make sure that we don't erase static fields with the instrumentDurableObjectWithSentry function. See an example below:

class MyDurableObjectBase extends DurableObject {
  public static readonly VERSION = '1.0.0';
}

const MyDurableObject = instrumentDurableObjectWithSentry(
  () => ({
    dsn: 'https://example.com/sentry',
    tracesSampleRate: 1.0,
  }),
  MyDurableObjectBase,
);

console.log(MyDurableObject.VERSION); // This will now work correctly

By moving the DurableObjectClass into it's own generic (new (state: DurableObjectState, env: E) => T), which we named C, it helps preserve the exact constructor type of the input class, including all its static properties and methods.

This was previously being lost by not aligning the DurableObjectClass with the function return value.

@AbhiPrasad AbhiPrasad requested a review from a team May 15, 2025 01:49
@AbhiPrasad AbhiPrasad self-assigned this May 15, 2025
@AbhiPrasad AbhiPrasad requested review from stephanie-anderson and s1gr1d and removed request for a team May 15, 2025 01:49
Copy link
Member

@mydea mydea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typescript magic :O

@AbhiPrasad AbhiPrasad merged commit 5b74eea into develop May 15, 2025
39 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-durable-object-type branch May 15, 2025 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Durable objects types breaks with new agents update
2 participants