Skip to content

Commit 4a1f2ac

Browse files
authored
fix(core): Export Scope interface as Scope (#12067)
To make interop with e.g. importing `Scope` from `@sentry/node` easier. Closes #12053
1 parent 4b18edd commit 4a1f2ac

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

packages/core/src/scope.ts

+17-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const DEFAULT_MAX_BREADCRUMBS = 100;
3434
/**
3535
* Holds additional event information.
3636
*/
37-
export class Scope implements ScopeInterface {
37+
class ScopeClass implements ScopeInterface {
3838
/** Flag if notifying is happening. */
3939
protected _notifyingListeners: boolean;
4040

@@ -116,8 +116,8 @@ export class Scope implements ScopeInterface {
116116
/**
117117
* @inheritDoc
118118
*/
119-
public clone(): Scope {
120-
const newScope = new Scope();
119+
public clone(): ScopeClass {
120+
const newScope = new ScopeClass();
121121
newScope._breadcrumbs = [...this._breadcrumbs];
122122
newScope._tags = { ...this._tags };
123123
newScope._extra = { ...this._extra };
@@ -587,6 +587,20 @@ export class Scope implements ScopeInterface {
587587
}
588588
}
589589

590+
// NOTE: By exporting this here as const & type, instead of doing `export class`,
591+
// We can get the correct class when importing from `@sentry/core`, but the original type (from `@sentry/types`)
592+
// This is helpful for interop, e.g. when doing `import type { Scope } from '@sentry/node';` (which re-exports this)
593+
594+
/**
595+
* Holds additional event information.
596+
*/
597+
export const Scope = ScopeClass;
598+
599+
/**
600+
* Holds additional event information.
601+
*/
602+
export type Scope = ScopeInterface;
603+
590604
function generatePropagationContext(): PropagationContext {
591605
return {
592606
traceId: uuid4(),

packages/core/test/lib/scope.test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -985,4 +985,15 @@ describe('withIsolationScope()', () => {
985985
done();
986986
});
987987
});
988+
989+
it('Scope type is equal to Scope from @sentry/types', () => {
990+
// We pass the Scope _class_ here to the callback,
991+
// Which actually is typed as using the Scope from @sentry/types
992+
// This should not TS-error, as we export the type from core as well
993+
const scope = withScope((scope: Scope) => {
994+
return scope;
995+
});
996+
997+
expect(scope).toBeDefined();
998+
});
988999
});

0 commit comments

Comments
 (0)