Skip to content

Commit 038453d

Browse files
authored
chore: Define type for Extra(s) (#2727)
1 parent b1f0c6a commit 038453d

File tree

7 files changed

+30
-11
lines changed

7 files changed

+30
-11
lines changed

packages/hub/src/hub.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
Client,
55
Event,
66
EventHint,
7+
Extra,
8+
Extras,
79
Hub as HubInterface,
810
Integration,
911
IntegrationClass,
@@ -287,7 +289,7 @@ export class Hub implements HubInterface {
287289
/**
288290
* @inheritDoc
289291
*/
290-
public setExtras(extras: { [key: string]: any }): void {
292+
public setExtras(extras: Extras): void {
291293
const top = this.getStackTop();
292294
if (!top.scope) {
293295
return;
@@ -309,7 +311,7 @@ export class Hub implements HubInterface {
309311
/**
310312
* @inheritDoc
311313
*/
312-
public setExtra(key: string, extra: any): void {
314+
public setExtra(key: string, extra: Extra): void {
313315
const top = this.getStackTop();
314316
if (!top.scope) {
315317
return;

packages/hub/src/scope.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
Event,
55
EventHint,
66
EventProcessor,
7+
Extra,
8+
Extras,
79
Scope as ScopeInterface,
810
ScopeContext,
911
Severity,
@@ -147,7 +149,7 @@ export class Scope implements ScopeInterface {
147149
/**
148150
* @inheritDoc
149151
*/
150-
public setExtras(extras: { [key: string]: any }): this {
152+
public setExtras(extras: Extras): this {
151153
this._extra = {
152154
...this._extra,
153155
...extras,
@@ -159,7 +161,7 @@ export class Scope implements ScopeInterface {
159161
/**
160162
* @inheritDoc
161163
*/
162-
public setExtra(key: string, extra: any): this {
164+
public setExtra(key: string, extra: Extra): this {
163165
this._extra = { ...this._extra, [key]: extra };
164166
this._notifyScopeListeners();
165167
return this;

packages/minimal/src/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import { getCurrentHub, Hub, Scope } from '@sentry/hub';
2-
import { Breadcrumb, CaptureContext, Event, Severity, Transaction, TransactionContext, User } from '@sentry/types';
2+
import {
3+
Breadcrumb,
4+
CaptureContext,
5+
Event,
6+
Extra,
7+
Extras,
8+
Severity,
9+
Transaction,
10+
TransactionContext,
11+
User,
12+
} from '@sentry/types';
313

414
/**
515
* This calls a function on the current hub.
@@ -105,7 +115,7 @@ export function setContext(name: string, context: { [key: string]: any } | null)
105115
* Set an object that will be merged sent as extra data with the event.
106116
* @param extras Extras object to merge into current context.
107117
*/
108-
export function setExtras(extras: { [key: string]: any }): void {
118+
export function setExtras(extras: Extras): void {
109119
callOnHub<void>('setExtras', extras);
110120
}
111121

@@ -123,7 +133,7 @@ export function setTags(tags: { [key: string]: string }): void {
123133
* @param extra Any kind of data. This data will be normalized.
124134
*/
125135

126-
export function setExtra(key: string, extra: any): void {
136+
export function setExtra(key: string, extra: Extra): void {
127137
callOnHub<void>('setExtra', key, extra);
128138
}
129139

packages/types/src/extra.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export type Extra = unknown;
2+
export type Extras = Record<string, Extra>;

packages/types/src/hub.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Breadcrumb, BreadcrumbHint } from './breadcrumb';
22
import { Client } from './client';
33
import { Event, EventHint } from './event';
4+
import { Extra, Extras } from './extra';
45
import { Integration, IntegrationClass } from './integration';
56
import { Scope } from './scope';
67
import { Severity } from './severity';
@@ -138,13 +139,13 @@ export interface Hub {
138139
* @param key String of extra
139140
* @param extra Any kind of data. This data will be normalized.
140141
*/
141-
setExtra(key: string, extra: any): void;
142+
setExtra(key: string, extra: Extra): void;
142143

143144
/**
144145
* Set an object that will be merged sent as extra data with the event.
145146
* @param extras Extras object to merge into current context.
146147
*/
147-
setExtras(extras: { [key: string]: any }): void;
148+
setExtras(extras: Extras): void;
148149

149150
/**
150151
* Sets context data with the given name.

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export { ExtendedError } from './error';
55
export { Event, EventHint } from './event';
66
export { EventProcessor } from './eventprocessor';
77
export { Exception } from './exception';
8+
export { Extra, Extras } from './extra';
89
export { Hub } from './hub';
910
export { Integration, IntegrationClass } from './integration';
1011
export { LogLevel } from './loglevel';

packages/types/src/scope.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Breadcrumb } from './breadcrumb';
22
import { EventProcessor } from './eventprocessor';
3+
import { Extra, Extras } from './extra';
34
import { Severity } from './severity';
45
import { Span } from './span';
56
import { Transaction } from './transaction';
@@ -50,14 +51,14 @@ export interface Scope {
5051
* Set an object that will be merged sent as extra data with the event.
5152
* @param extras Extras object to merge into current context.
5253
*/
53-
setExtras(extras: { [key: string]: any }): this;
54+
setExtras(extras: Extras): this;
5455

5556
/**
5657
* Set key:value that will be sent as extra data with the event.
5758
* @param key String of extra
5859
* @param extra Any kind of data. This data will be normailzed.
5960
*/
60-
setExtra(key: string, extra: any): this;
61+
setExtra(key: string, extra: Extra): this;
6162

6263
/**
6364
* Sets the fingerprint on the scope to send with the events.

0 commit comments

Comments
 (0)