Skip to content

Commit

Permalink
chore: Define type for Extra(s) (#2727)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Jul 8, 2020
1 parent b1f0c6a commit 038453d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 11 deletions.
6 changes: 4 additions & 2 deletions packages/hub/src/hub.ts
Expand Up @@ -4,6 +4,8 @@ import {
Client,
Event,
EventHint,
Extra,
Extras,
Hub as HubInterface,
Integration,
IntegrationClass,
Expand Down Expand Up @@ -287,7 +289,7 @@ export class Hub implements HubInterface {
/**
* @inheritDoc
*/
public setExtras(extras: { [key: string]: any }): void {
public setExtras(extras: Extras): void {
const top = this.getStackTop();
if (!top.scope) {
return;
Expand All @@ -309,7 +311,7 @@ export class Hub implements HubInterface {
/**
* @inheritDoc
*/
public setExtra(key: string, extra: any): void {
public setExtra(key: string, extra: Extra): void {
const top = this.getStackTop();
if (!top.scope) {
return;
Expand Down
6 changes: 4 additions & 2 deletions packages/hub/src/scope.ts
Expand Up @@ -4,6 +4,8 @@ import {
Event,
EventHint,
EventProcessor,
Extra,
Extras,
Scope as ScopeInterface,
ScopeContext,
Severity,
Expand Down Expand Up @@ -147,7 +149,7 @@ export class Scope implements ScopeInterface {
/**
* @inheritDoc
*/
public setExtras(extras: { [key: string]: any }): this {
public setExtras(extras: Extras): this {
this._extra = {
...this._extra,
...extras,
Expand All @@ -159,7 +161,7 @@ export class Scope implements ScopeInterface {
/**
* @inheritDoc
*/
public setExtra(key: string, extra: any): this {
public setExtra(key: string, extra: Extra): this {
this._extra = { ...this._extra, [key]: extra };
this._notifyScopeListeners();
return this;
Expand Down
16 changes: 13 additions & 3 deletions packages/minimal/src/index.ts
@@ -1,5 +1,15 @@
import { getCurrentHub, Hub, Scope } from '@sentry/hub';
import { Breadcrumb, CaptureContext, Event, Severity, Transaction, TransactionContext, User } from '@sentry/types';
import {
Breadcrumb,
CaptureContext,
Event,
Extra,
Extras,
Severity,
Transaction,
TransactionContext,
User,
} from '@sentry/types';

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

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

export function setExtra(key: string, extra: any): void {
export function setExtra(key: string, extra: Extra): void {
callOnHub<void>('setExtra', key, extra);
}

Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/extra.ts
@@ -0,0 +1,2 @@
export type Extra = unknown;
export type Extras = Record<string, Extra>;
5 changes: 3 additions & 2 deletions packages/types/src/hub.ts
@@ -1,6 +1,7 @@
import { Breadcrumb, BreadcrumbHint } from './breadcrumb';
import { Client } from './client';
import { Event, EventHint } from './event';
import { Extra, Extras } from './extra';
import { Integration, IntegrationClass } from './integration';
import { Scope } from './scope';
import { Severity } from './severity';
Expand Down Expand Up @@ -138,13 +139,13 @@ export interface Hub {
* @param key String of extra
* @param extra Any kind of data. This data will be normalized.
*/
setExtra(key: string, extra: any): void;
setExtra(key: string, extra: Extra): void;

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

/**
* Sets context data with the given name.
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Expand Up @@ -5,6 +5,7 @@ export { ExtendedError } from './error';
export { Event, EventHint } from './event';
export { EventProcessor } from './eventprocessor';
export { Exception } from './exception';
export { Extra, Extras } from './extra';
export { Hub } from './hub';
export { Integration, IntegrationClass } from './integration';
export { LogLevel } from './loglevel';
Expand Down
5 changes: 3 additions & 2 deletions packages/types/src/scope.ts
@@ -1,5 +1,6 @@
import { Breadcrumb } from './breadcrumb';
import { EventProcessor } from './eventprocessor';
import { Extra, Extras } from './extra';
import { Severity } from './severity';
import { Span } from './span';
import { Transaction } from './transaction';
Expand Down Expand Up @@ -50,14 +51,14 @@ export interface Scope {
* Set an object that will be merged sent as extra data with the event.
* @param extras Extras object to merge into current context.
*/
setExtras(extras: { [key: string]: any }): this;
setExtras(extras: Extras): this;

/**
* Set key:value that will be sent as extra data with the event.
* @param key String of extra
* @param extra Any kind of data. This data will be normailzed.
*/
setExtra(key: string, extra: any): this;
setExtra(key: string, extra: Extra): this;

/**
* Sets the fingerprint on the scope to send with the events.
Expand Down

0 comments on commit 038453d

Please sign in to comment.