diff --git a/packages/hub/src/scope.ts b/packages/hub/src/scope.ts index 82d470a265db..ffc8cdd7f4ac 100644 --- a/packages/hub/src/scope.ts +++ b/packages/hub/src/scope.ts @@ -45,7 +45,7 @@ export class Scope implements ScopeInterface { /** Contexts */ // eslint-disable-next-line @typescript-eslint/no-explicit-any - protected _contexts: { [key: string]: any } = {}; + protected _contexts: { [key: string]: Record } = {}; /** Fingerprint */ protected _fingerprint?: string[]; @@ -185,9 +185,14 @@ export class Scope implements ScopeInterface { /** * @inheritDoc */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - public setContext(key: string, context: { [key: string]: any } | null): this { - this._contexts = { ...this._contexts, [key]: context }; + public setContext(key: string, context: { [key: string]: Record } | null): this { + if (context === null) { + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete + delete this._contexts[key]; + } else { + this._contexts = { ...this._contexts, [key]: context }; + } + this._notifyScopeListeners(); return this; } diff --git a/packages/types/src/scope.ts b/packages/types/src/scope.ts index 4b5f5cb4736d..589940d92c50 100644 --- a/packages/types/src/scope.ts +++ b/packages/types/src/scope.ts @@ -14,7 +14,7 @@ export interface ScopeContext { user: User; level: Severity; extra: { [key: string]: any }; - contexts: { [key: string]: any }; + contexts: { [key: string]: Record }; tags: { [key: string]: string }; fingerprint: string[]; }