Skip to content

Commit 2b8687f

Browse files
committed
Better typings for SentryWrappedFunction
1 parent 818b404 commit 2b8687f

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

packages/browser/src/integrations/helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export function wrap(
4141
return fn;
4242
}
4343
// If this has already been wrapped in the past, return that wrapped function
44-
if (fn.__sentry_wrapper__) {
45-
return fn.__sentry_wrapper__;
44+
if (fn.__sentry_wrapped__) {
45+
return fn.__sentry_wrapped__;
4646
}
4747
} catch (e) {
4848
// Just accessing custom props in some Selenium environments
@@ -97,7 +97,7 @@ export function wrap(
9797
} catch (_oO) {} // tslint:disable-line:no-empty
9898

9999
wrapped.prototype = fn.prototype;
100-
fn.__sentry_wrapper__ = wrapped;
100+
fn.__sentry_wrapped__ = wrapped;
101101

102102
// Signal that this function has been wrapped/filled already
103103
// for both debugging and to prevent it to being wrapped/filled twice

packages/browser/src/integrations/trycatch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ export class TryCatch implements Integration {
149149
): () => void {
150150
let callback = (fn as any) as SentryWrappedFunction;
151151
try {
152-
callback = callback && (callback.__sentry_wrapper__ || callback);
152+
callback = callback && (callback.__sentry_wrapped__ || callback);
153153
} catch (e) {
154-
// ignore, accessing __sentry_wrapper__ will throw in some Selenium environments
154+
// ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
155155
}
156156
return original.call(this, eventName, callback, options);
157157
};

packages/core/src/baseclient.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
SentryEvent,
66
SentryEventHint,
77
SentryResponse,
8+
SentryWrappedFunction,
89
Severity,
910
Status,
1011
} from '@sentry/types';
@@ -23,7 +24,7 @@ interface ExtensibleConsole extends Console {
2324
async function beforeBreadcrumbConsoleLoopGuard(
2425
callback: () => Breadcrumb | Promise<Breadcrumb | null> | null,
2526
): Promise<Breadcrumb | null> {
26-
const global = getGlobalObject();
27+
const global = getGlobalObject() as Window;
2728
const levels = ['debug', 'info', 'warn', 'error', 'log'];
2829

2930
if (!('console' in global)) {
@@ -34,8 +35,8 @@ async function beforeBreadcrumbConsoleLoopGuard(
3435

3536
// Restore all wrapped console methods
3637
levels.forEach(level => {
37-
if (level in global.console && originalConsole[level].__sentry__) {
38-
originalConsole[level] = originalConsole[level].__sentry_original__;
38+
if (level in global.console && (originalConsole[level] as SentryWrappedFunction).__sentry__) {
39+
originalConsole[level] = (originalConsole[level] as SentryWrappedFunction).__sentry_original__;
3940
}
4041
});
4142

@@ -44,8 +45,8 @@ async function beforeBreadcrumbConsoleLoopGuard(
4445

4546
// Revert restoration to wrapped state
4647
levels.forEach(level => {
47-
if (level in global.console && originalConsole[level].__sentry__) {
48-
originalConsole[level] = originalConsole[level].__sentry_wrapped__;
48+
if (level in global.console && (originalConsole[level] as SentryWrappedFunction).__sentry__) {
49+
originalConsole[level] = (originalConsole[level] as SentryWrappedFunction).__sentry_wrapped__;
4950
}
5051
});
5152

packages/types/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ export namespace Status {
280280
export interface SentryWrappedFunction extends Function {
281281
[key: string]: any;
282282
__sentry__?: boolean;
283-
__sentry_wrapper__?: SentryWrappedFunction;
283+
__sentry_wrapped__?: SentryWrappedFunction;
284284
__sentry_original__?: SentryWrappedFunction;
285285
}
286286

packages/utils/src/object.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SentryWrappedFunction } from '@sentry/types';
12
import { isPlainObject, isUndefined } from './is';
23

34
/**
@@ -156,14 +157,12 @@ export function fill(source: { [key: string]: any }, name: string, replacement:
156157
if (!(name in source)) {
157158
return;
158159
}
159-
const original = source[name];
160-
source[name] = replacement(original);
161-
// tslint:disable-next-line:no-unsafe-any
162-
source[name].__sentry__ = true;
163-
// tslint:disable-next-line:no-unsafe-any
164-
source[name].__sentry_original__ = original;
165-
// tslint:disable-next-line:no-unsafe-any
166-
source[name].__sentry_wrapped__ = source[name];
160+
const original = source[name] as () => any;
161+
const wrapped = replacement(original) as SentryWrappedFunction;
162+
wrapped.__sentry__ = true;
163+
wrapped.__sentry_original__ = original;
164+
wrapped.__sentry_wrapped__ = wrapped;
165+
source[name] = wrapped;
167166
}
168167

169168
/**

0 commit comments

Comments
 (0)