Skip to content

Commit 57b520e

Browse files
fix: improve usage of types
1 parent 62d2571 commit 57b520e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

packages/browser/src/integrations/breadcrumbs.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ interface BreadcrumbIntegrations {
4040
xhr?: boolean;
4141
}
4242

43+
type XMLHttpRequestProp = 'onload' | 'onerror' | 'onprogress';
44+
4345
/** Default Breadcrumbs instrumentations */
4446
export class Breadcrumbs implements Integration {
4547
/**
@@ -80,8 +82,8 @@ export class Breadcrumbs implements Integration {
8082
return;
8183
}
8284

83-
fill(global.console, level, function(originalConsoleLevel: () => any): any {
84-
return function(...args: any[]): any {
85+
fill(global.console, level, function(originalConsoleLevel: () => any): Function {
86+
return function(...args: any[]): void {
8587
const breadcrumbData = {
8688
category: 'console',
8789
data: {
@@ -151,7 +153,7 @@ export class Breadcrumbs implements Integration {
151153
fn: EventListenerOrEventListenerObject,
152154
options?: boolean | AddEventListenerOptions,
153155
): (eventName: string, fn: EventListenerOrEventListenerObject, capture?: boolean, secure?: boolean) => void {
154-
if (fn && (fn as any).handleEvent) {
156+
if (fn && (fn as EventListenerObject).handleEvent) {
155157
if (eventName === 'click') {
156158
fill(fn, 'handleEvent', function(innerOriginal: () => void): (caughtEvent: Event) => void {
157159
return function(this: any, event: Event): (event: Event) => void {
@@ -195,7 +197,7 @@ export class Breadcrumbs implements Integration {
195197
fn: EventListenerObject,
196198
options?: boolean | EventListenerOptions,
197199
): () => void {
198-
let callback = (fn as any) as WrappedFunction;
200+
let callback = fn as WrappedFunction;
199201
try {
200202
callback = callback && (callback.__sentry_wrapped__ || callback);
201203
} catch (e) {
@@ -375,9 +377,8 @@ export class Breadcrumbs implements Integration {
375377
/**
376378
* @hidden
377379
*/
378-
function wrapProp(prop: string, xhr: XMLHttpRequest): void {
379-
// TODO: Fix XHR types
380-
if (prop in xhr && typeof (xhr as { [key: string]: any })[prop] === 'function') {
380+
function wrapProp(prop: XMLHttpRequestProp, xhr: XMLHttpRequest): void {
381+
if (prop in xhr && typeof xhr[prop] === 'function') {
381382
fill(xhr, prop, original =>
382383
wrap(original, {
383384
mechanism: {
@@ -461,7 +462,8 @@ export class Breadcrumbs implements Integration {
461462
}
462463
}
463464

464-
['onload', 'onerror', 'onprogress'].forEach(prop => {
465+
const xmlHttpRequestProps: XMLHttpRequestProp[] = ['onload', 'onerror', 'onprogress'];
466+
xmlHttpRequestProps.forEach(prop => {
465467
wrapProp(prop, xhr);
466468
});
467469

@@ -534,7 +536,7 @@ export class Breadcrumbs implements Integration {
534536
function addSentryBreadcrumb(serializedData: string): void {
535537
// There's always something that can go wrong with deserialization...
536538
try {
537-
const event: { [key: string]: any } = JSON.parse(serializedData);
539+
const event = JSON.parse(serializedData);
538540
Breadcrumbs.addBreadcrumb(
539541
{
540542
category: 'sentry',

0 commit comments

Comments
 (0)