Skip to content

Commit 745775e

Browse files
authored
ref: Refactor some more any types (#14546)
Getting rid of some more `any` types.
1 parent 4103667 commit 745775e

File tree

22 files changed

+47
-77
lines changed

22 files changed

+47
-77
lines changed

packages/angular/src/tracing.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,9 @@ export class TraceDirective implements OnInit, AfterViewInit {
271271
* @inheritdoc
272272
*/
273273
public ngAfterViewInit(): void {
274-
if (this._tracingSpan) {
275-
runOutsideAngular(() => this._tracingSpan!.end());
274+
const span = this._tracingSpan;
275+
if (span) {
276+
runOutsideAngular(() => span.end());
276277
}
277278
}
278279
}
@@ -302,8 +303,7 @@ export function TraceClass(options?: TraceClassOptions): ClassDecorator {
302303
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
303304
return target => {
304305
const originalOnInit = target.prototype.ngOnInit;
305-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
306-
target.prototype.ngOnInit = function (...args: any[]): ReturnType<typeof originalOnInit> {
306+
target.prototype.ngOnInit = function (...args: unknown[]): ReturnType<typeof originalOnInit> {
307307
tracingSpan = runOutsideAngular(() =>
308308
startInactiveSpan({
309309
onlyIfParent: true,
@@ -321,8 +321,7 @@ export function TraceClass(options?: TraceClassOptions): ClassDecorator {
321321
};
322322

323323
const originalAfterViewInit = target.prototype.ngAfterViewInit;
324-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
325-
target.prototype.ngAfterViewInit = function (...args: any[]): ReturnType<typeof originalAfterViewInit> {
324+
target.prototype.ngAfterViewInit = function (...args: unknown[]): ReturnType<typeof originalAfterViewInit> {
326325
if (tracingSpan) {
327326
runOutsideAngular(() => tracingSpan.end());
328327
}
@@ -345,11 +344,9 @@ interface TraceMethodOptions {
345344
* Decorator function that can be used to capture a single lifecycle methods of the component.
346345
*/
347346
export function TraceMethod(options?: TraceMethodOptions): MethodDecorator {
348-
// eslint-disable-next-line @typescript-eslint/ban-types
349-
return (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
347+
return (_target: unknown, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {
350348
const originalMethod = descriptor.value;
351-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
352-
descriptor.value = function (...args: any[]): ReturnType<typeof originalMethod> {
349+
descriptor.value = function (...args: unknown[]): ReturnType<typeof originalMethod> {
353350
const now = timestampInSeconds();
354351

355352
runOutsideAngular(() => {

packages/browser/src/integrations/globalhandlers.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,12 @@ function _eventFromRejectionWithPrimitive(reason: Primitive): Event {
153153
};
154154
}
155155

156-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
157-
function _enhanceEventWithInitialFrame(event: Event, url: any, line: any, column: any): Event {
156+
function _enhanceEventWithInitialFrame(
157+
event: Event,
158+
url: string | undefined,
159+
line: number | undefined,
160+
column: number | undefined,
161+
): Event {
158162
// event.exception
159163
const e = (event.exception = event.exception || {});
160164
// event.exception.values
@@ -166,8 +170,8 @@ function _enhanceEventWithInitialFrame(event: Event, url: any, line: any, column
166170
// event.exception.values[0].stacktrace.frames
167171
const ev0sf = (ev0s.frames = ev0s.frames || []);
168172

169-
const colno = isNaN(parseInt(column, 10)) ? undefined : column;
170-
const lineno = isNaN(parseInt(line, 10)) ? undefined : line;
173+
const colno = column;
174+
const lineno = line;
171175
const filename = isString(url) && url.length > 0 ? url : getLocationHref();
172176

173177
// event.exception.values[0].stacktrace.frames

packages/browser/src/sdk.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ export function init(browserOptions: BrowserOptions = {}): Client | undefined {
198198
* All properties the report dialog supports
199199
*/
200200
export interface ReportDialogOptions {
201+
// TODO(v9): Change this to [key: string]: unknkown;
201202
// eslint-disable-next-line @typescript-eslint/no-explicit-any
202203
[key: string]: any;
203204
eventId?: string;

packages/core/src/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export function getEnvelopeEndpointWithUrlEncodedAuth(dsn: DsnComponents, tunnel
4747
export function getReportDialogEndpoint(
4848
dsnLike: DsnLike,
4949
dialogOptions: {
50+
// TODO(v9): Change this to [key: string]: unknown;
5051
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5152
[key: string]: any;
5253
user?: { name?: string; email?: string };

packages/core/src/baseclient.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
158158
/**
159159
* @inheritDoc
160160
*/
161-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
162-
public captureException(exception: any, hint?: EventHint, scope?: Scope): string {
161+
public captureException(exception: unknown, hint?: EventHint, scope?: Scope): string {
163162
const eventId = uuid4();
164163

165164
// ensure we haven't captured this very object before
@@ -915,8 +914,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
915914
/**
916915
* @inheritDoc
917916
*/
918-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
919-
public abstract eventFromException(_exception: any, _hint?: EventHint): PromiseLike<Event>;
917+
public abstract eventFromException(_exception: unknown, _hint?: EventHint): PromiseLike<Event>;
920918

921919
/**
922920
* @inheritDoc

packages/core/src/exports.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ import { parseEventHintOrCaptureContext } from './utils/prepareEvent';
3434
* @param hint Optional additional data to attach to the Sentry event.
3535
* @returns the id of the captured Sentry event.
3636
*/
37-
export function captureException(
38-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
39-
exception: any,
40-
hint?: ExclusiveEventHintOrCaptureContext,
41-
): string {
37+
export function captureException(exception: unknown, hint?: ExclusiveEventHintOrCaptureContext): string {
4238
return getCurrentScope().captureException(exception, parseEventHintOrCaptureContext(hint));
4339
}
4440

@@ -73,8 +69,7 @@ export function captureEvent(event: Event, hint?: EventHint): string {
7369
* @param name of the context
7470
* @param context Any kind of data. This data will be normalized.
7571
*/
76-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
77-
export function setContext(name: string, context: { [key: string]: any } | null): void {
72+
export function setContext(name: string, context: { [key: string]: unknown } | null): void {
7873
getIsolationScope().setContext(name, context);
7974
}
8075

packages/core/src/fetch.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ type PolymorphicRequestHeaders =
1414
| Array<[string, string]>
1515
// the below is not precisely the Header type used in Request, but it'll pass duck-typing
1616
| {
17-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
18-
[key: string]: any;
1917
append: (key: string, value: string) => void;
2018
get: (key: string) => string | null | undefined;
2119
};

packages/core/src/integrations/functiontostring.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ const _functionToStringIntegration = (() => {
1919
// intrinsics (like Function.prototype) might be immutable in some environments
2020
// e.g. Node with --frozen-intrinsics, XS (an embedded JavaScript engine) or SES (a JavaScript proposal)
2121
try {
22-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
23-
Function.prototype.toString = function (this: WrappedFunction, ...args: any[]): string {
22+
Function.prototype.toString = function (this: WrappedFunction, ...args: unknown[]): string {
2423
const originalFunction = getOriginalFunction(this);
2524
const context =
2625
SETUP_CLIENTS.has(getClient() as Client) && originalFunction !== undefined ? originalFunction : this;

packages/core/src/metrics/aggregator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class MetricsAggregator implements MetricsAggregatorBase {
2020
// that we store in memory.
2121
private _bucketsTotalWeight;
2222

23-
// We adjust the type here to add the `unref()` part, as setInterval can technically return a number of a NodeJS.Timer.
23+
// We adjust the type here to add the `unref()` part, as setInterval can technically return a number or a NodeJS.Timer
2424
private readonly _interval: ReturnType<typeof setInterval> & { unref?: () => void };
2525

2626
// SDKs are required to shift the flush interval by random() * rollup_in_seconds.

packages/core/src/server-runtime-client.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ export class ServerRuntimeClient<
7979
/**
8080
* @inheritDoc
8181
*/
82-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
83-
public captureException(exception: any, hint?: EventHint, scope?: Scope): string {
82+
public captureException(exception: unknown, hint?: EventHint, scope?: Scope): string {
8483
// Check if `_sessionFlusher` exists because it is initialized (defined) only when the `autoSessionTracking` is enabled.
8584
// The expectation is that session aggregates are only sent when `autoSessionTracking` is enabled.
8685
// TODO(v9): Our goal in the future is to not have the `autoSessionTracking` option and instead rely on integrations doing the creation and sending of sessions. We will not have a central kill-switch for sessions.

packages/core/src/sessionflusher.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ export class SessionFlusher implements SessionFlusherLike {
2222
public readonly flushTimeout: number;
2323
private _pendingAggregates: Map<number, AggregationCounts>;
2424
private _sessionAttrs: ReleaseHealthAttributes;
25-
// Cast to any so that it can use Node.js timeout
26-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
27-
private _intervalId: any;
25+
// We adjust the type here to add the `unref()` part, as setInterval can technically return a number or a NodeJS.Timer
26+
private readonly _intervalId: ReturnType<typeof setInterval> & { unref?: () => void };
2827
private _isEnabled: boolean;
2928
private _client: Client;
3029

@@ -36,9 +35,7 @@ export class SessionFlusher implements SessionFlusherLike {
3635

3736
// Call to setInterval, so that flush is called every 60 seconds.
3837
this._intervalId = setInterval(() => this.flush(), this.flushTimeout * 1000);
39-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
4038
if (this._intervalId.unref) {
41-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
4239
this._intervalId.unref();
4340
}
4441
this._sessionAttrs = attrs;

packages/core/src/utils-hoist/instrument/globalError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function addGlobalErrorInstrumentationHandler(handler: (data: HandlerData
2020
function instrumentError(): void {
2121
_oldOnErrorHandler = GLOBAL_OBJ.onerror;
2222

23-
// Note: The reason we are doing window.onerror instead of window.addEventListener('error') is
23+
// Note: The reason we are doing window.onerror instead of window.addEventListener('error')
2424
// is that we are using this handler in the Loader Script, to handle buffered errors consistently
2525
GLOBAL_OBJ.onerror = function (
2626
msg: string | object,

packages/core/src/utils-hoist/instrument/globalUnhandledRejection.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { HandlerDataUnhandledRejection } from '../../types-hoist';
2-
32
import { GLOBAL_OBJ } from '../worldwide';
43
import { addHandler, maybeInstrument, triggerHandlers } from './handlers';
54

@@ -22,7 +21,7 @@ export function addGlobalUnhandledRejectionInstrumentationHandler(
2221
function instrumentUnhandledRejection(): void {
2322
_oldOnUnhandledRejectionHandler = GLOBAL_OBJ.onunhandledrejection;
2423

25-
// Note: The reason we are doing window.onerror instead of window.addEventListener('unhandledrejection') is
24+
// Note: The reason we are doing window.onunhandledrejection instead of window.addEventListener('unhandledrejection')
2625
// is that we are using this handler in the Loader Script, to handle buffered rejections consistently
2726
GLOBAL_OBJ.onunhandledrejection = function (e: unknown): boolean {
2827
const handlerData: HandlerDataUnhandledRejection = e;

packages/core/src/utils-hoist/logger.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ type LoggerConsoleMethods = Record<ConsoleLevel, LoggerMethod>;
2121

2222
/** This may be mutated by the console instrumentation. */
2323
export const originalConsoleMethods: {
24-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
25-
[key in ConsoleLevel]?: (...args: any[]) => void;
24+
[key in ConsoleLevel]?: (...args: unknown[]) => void;
2625
} = {};
2726

2827
/** JSDoc */
@@ -79,8 +78,7 @@ function makeLogger(): Logger {
7978

8079
if (DEBUG_BUILD) {
8180
CONSOLE_LEVELS.forEach(name => {
82-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
83-
logger[name] = (...args: any[]) => {
81+
logger[name] = (...args: Parameters<(typeof GLOBAL_OBJ.console)[typeof name]>) => {
8482
if (enabled) {
8583
consoleSandbox(() => {
8684
GLOBAL_OBJ.console[name](`${PREFIX}[${name}]:`, ...args);

packages/core/src/utils-hoist/misc.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
21
import type { Event, Exception, Mechanism, StackFrame } from '../types-hoist';
32

43
import { addNonEnumerableProperty } from './object';

packages/core/src/utils-hoist/object.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ export function getOriginalFunction<T extends Function>(func: WrappedFunction<T>
9494
*
9595
* @deprecated This function is deprecated and will be removed in the next major version of the SDK.
9696
*/
97+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9798
export function urlEncode(object: { [key: string]: any }): string {
98-
return Object.keys(object)
99-
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(object[key])}`)
99+
return Object.entries(object)
100+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
100101
.join('&');
101102
}
102103

@@ -237,7 +238,7 @@ function _dropUndefinedKeys<T>(inputValue: T, memoizationMap: Map<unknown, unkno
237238
return memoVal as T;
238239
}
239240

240-
const returnValue: { [key: string]: any } = {};
241+
const returnValue: { [key: string]: unknown } = {};
241242
// Store the mapping of this value in case we visit it again, in case of circular data
242243
memoizationMap.set(inputValue, returnValue);
243244

packages/core/src/utils-hoist/string.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ export function snipLine(line: string, colno: number): string {
6565
* @param delimiter string to be placed in-between values
6666
* @returns Joined values
6767
*/
68-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
69-
export function safeJoin(input: any[], delimiter?: string): string {
68+
export function safeJoin(input: unknown[], delimiter?: string): string {
7069
if (!Array.isArray(input)) {
7170
return '';
7271
}

packages/core/src/utils-hoist/vendor/supportsHistory.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ export function supportsHistory(): boolean {
3535
// NOTE: in Chrome App environment, touching history.pushState, *even inside
3636
// a try/catch block*, will cause Chrome to output an error to console.error
3737
// borrowed from: https://github.com/angular/angular.js/pull/13945/files
38-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
39-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
40-
const chromeVar = (WINDOW as any).chrome;
38+
// TODO(v9): Remove this custom check, it is pretty old and likely not needed anymore
39+
const chromeVar = (WINDOW as { chrome?: { app?: { runtime?: unknown } } }).chrome;
4140
const isChromePackagedApp = chromeVar && chromeVar.app && chromeVar.app.runtime;
42-
/* eslint-enable @typescript-eslint/no-unsafe-member-access */
4341
const hasHistoryApi = 'history' in WINDOW && !!WINDOW.history.pushState && !!WINDOW.history.replaceState;
4442

4543
return !isChromePackagedApp && hasHistoryApi;

packages/nestjs/src/decorators.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import { isExpectedError } from './helpers';
99
*/
1010
export const SentryCron = (monitorSlug: string, monitorConfig?: MonitorConfig): MethodDecorator => {
1111
return (target: unknown, propertyKey, descriptor: PropertyDescriptor) => {
12-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
13-
const originalMethod = descriptor.value as (...args: any[]) => Promise<any>;
12+
const originalMethod = descriptor.value as (...args: unknown[]) => Promise<unknown>;
1413

15-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
16-
descriptor.value = function (...args: any[]) {
14+
descriptor.value = function (...args: unknown[]) {
1715
return Sentry.withMonitor(
1816
monitorSlug,
1917
() => {
@@ -31,11 +29,9 @@ export const SentryCron = (monitorSlug: string, monitorConfig?: MonitorConfig):
3129
*/
3230
export function SentryTraced(op: string = 'function') {
3331
return function (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) {
34-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
35-
const originalMethod = descriptor.value as (...args: any[]) => Promise<any> | any; // function can be sync or async
32+
const originalMethod = descriptor.value as (...args: unknown[]) => Promise<unknown> | unknown; // function can be sync or async
3633

37-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
38-
descriptor.value = function (...args: any[]) {
34+
descriptor.value = function (...args: unknown[]) {
3935
return startSpan(
4036
{
4137
op: op,
@@ -64,11 +60,9 @@ export function SentryTraced(op: string = 'function') {
6460
*/
6561
export function SentryExceptionCaptured() {
6662
return function (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) {
67-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
68-
const originalCatch = descriptor.value as (exception: unknown, host: unknown, ...args: any[]) => void;
63+
const originalCatch = descriptor.value as (exception: unknown, host: unknown, ...args: unknown[]) => void;
6964

70-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
71-
descriptor.value = function (exception: unknown, host: unknown, ...args: any[]) {
65+
descriptor.value = function (exception: unknown, host: unknown, ...args: unknown[]) {
7266
if (isExpectedError(exception)) {
7367
return originalCatch.apply(this, [exception, host, ...args]);
7468
}

packages/node/src/integrations/onunhandledrejection.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,8 @@ export function makeUnhandledPromiseHandler(
6363

6464
/**
6565
* Handler for `mode` option
66-
6766
*/
68-
function handleRejection(
69-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
70-
reason: any,
71-
options: OnUnhandledRejectionOptions,
72-
): void {
67+
function handleRejection(reason: unknown, options: OnUnhandledRejectionOptions): void {
7368
// https://github.com/nodejs/node/blob/7cf6f9e964aa00772965391c23acda6d71972a9a/lib/internal/process/promises.js#L234-L240
7469
const rejectionWarning =
7570
'This error originated either by ' +
@@ -81,8 +76,7 @@ function handleRejection(
8176
if (options.mode === 'warn') {
8277
consoleSandbox(() => {
8378
console.warn(rejectionWarning);
84-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
85-
console.error(reason && reason.stack ? reason.stack : reason);
79+
console.error(reason && typeof reason === 'object' && 'stack' in reason ? reason.stack : reason);
8680
});
8781
} else if (options.mode === 'strict') {
8882
consoleSandbox(() => {

packages/node/src/utils/errorhandling.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const DEFAULT_SHUTDOWN_TIMEOUT = 2000;
77
/**
88
* @hidden
99
*/
10-
export function logAndExitProcess(error: Error): void {
10+
export function logAndExitProcess(error: unknown): void {
1111
consoleSandbox(() => {
1212
// eslint-disable-next-line no-console
1313
console.error(error);

packages/solid/src/errorboundary.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ export function withSentryErrorBoundary(ErrorBoundary: Component<ErrorBoundaryPr
1616
const SentryErrorBoundary = (props: ErrorBoundaryProps): JSX.Element => {
1717
const [local, others] = splitProps(props, ['fallback']);
1818

19-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
20-
const fallback = (error: any, reset: () => void): JSX.Element => {
19+
const fallback = (error: unknown, reset: () => void): JSX.Element => {
2120
captureException(error);
2221

2322
const f = local.fallback;

0 commit comments

Comments
 (0)