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.

0 commit comments

Comments
 (0)