Skip to content

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 s1gr1d and stephanie-anderson 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

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