From 9fcac11a263edf58a835d0d1d046f87a33eb46f3 Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 10 Dec 2025 13:40:57 -0800 Subject: [PATCH] chore(lint): prefer 'unknown' to 'any', fix lint warnings Explicitly enable `any` usage in typescript in: - `dev-packages`, since those are largely integration and E2E tests. (This is done with the addition of a `dev-packages/.eslintrc.js` file.) - `packages/*/test/`, since those are all tests. (This is done with a rule override added to the root `.eslintrc.js` file.) - Several one-off allowances, generally for vendored types from third party sources, and cases involving function type extension/overriding that TypeScript can't follow. (These are done with file/line overrides, explicit `as` casting, and adding type inference to the `isInstanceOf` method.) In other places (ie, in exported production code paths), replace `any` with `unknown`, and upgrade the `@typescript/no-explicit-any` lint rule to an error. This silences a lot of eslint warnings that were habitually ignored, and encourages us to not opt out of strict type safety in our exported code. --- .eslintrc.js | 6 ++++++ dev-packages/.eslintrc.js | 7 +++++++ .../browser-integration-tests/.eslintrc.js | 2 +- dev-packages/bundler-tests/.eslintrc.js | 2 +- dev-packages/clear-cache-gh-action/.eslintrc.cjs | 2 +- .../cloudflare-integration-tests/.eslintrc.js | 2 +- .../suites/tracing/google-genai/mocks.ts | 1 - dev-packages/e2e-tests/.eslintrc.js | 2 +- .../external-contributor-gh-action/.eslintrc.cjs | 2 +- .../node-core-integration-tests/.eslintrc.js | 2 +- dev-packages/node-integration-tests/.eslintrc.js | 2 +- dev-packages/node-overhead-gh-action/.eslintrc.cjs | 2 +- dev-packages/rollup-utils/.eslintrc.cjs | 2 +- dev-packages/size-limit-gh-action/.eslintrc.cjs | 2 +- dev-packages/test-utils/.eslintrc.js | 2 +- .../instrumentation-aws-lambda/types.ts | 1 + packages/cloudflare/src/durableobject.ts | 14 +++++++------- packages/core/src/integrations/supabase.ts | 1 + packages/core/src/types-hoist/breadcrumb.ts | 3 +++ packages/core/src/types-hoist/context.ts | 1 + packages/core/src/types-hoist/error.ts | 2 +- packages/core/src/types-hoist/event.ts | 1 + packages/core/src/types-hoist/instrument.ts | 2 ++ packages/core/src/types-hoist/integration.ts | 1 + packages/core/src/types-hoist/misc.ts | 2 +- packages/core/src/types-hoist/polymorphics.ts | 4 ++++ packages/core/src/types-hoist/samplingcontext.ts | 2 +- packages/core/src/types-hoist/stackframe.ts | 4 ++-- packages/core/src/types-hoist/user.ts | 2 +- packages/core/src/utils/aggregate-errors.ts | 4 ++-- packages/core/src/utils/is.ts | 2 +- packages/core/test/lib/utils/is.test.ts | 11 ++++++++++- packages/feedback/src/modal/integration.tsx | 4 ++-- packages/nextjs/src/config/types.ts | 4 ++-- .../node/src/integrations/tracing/fastify/types.ts | 1 + .../tracing/fastify/v3/instrumentation.ts | 1 + .../src/integrations/tracing/fastify/v3/types.ts | 1 + .../src/integrations/tracing/fastify/v3/utils.ts | 1 + .../tracing/firebase/otel/patches/firestore.ts | 2 ++ .../integrations/tracing/firebase/otel/types.ts | 1 + .../node/src/integrations/tracing/postgresjs.ts | 1 + packages/remix/src/utils/types.ts | 3 ++- packages/remix/src/vendor/instrumentation.ts | 3 +++ packages/replay-internal/rollup.npm.config.mjs | 1 + packages/replay-internal/src/types/rrweb.ts | 2 ++ .../async-local-storage-context-manager.ts | 3 ++- packages/vercel-edge/test/wintercg-fetch.test.ts | 3 +-- packages/vue/src/pinia.ts | 6 +++--- 48 files changed, 91 insertions(+), 41 deletions(-) create mode 100644 dev-packages/.eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js index 5266f0117a89..ca67fc429584 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -23,6 +23,9 @@ module.exports = { 'types/**', 'scripts/*.js', ], + rules: { + '@typescript-eslint/no-explicit-any': 'error', + }, reportUnusedDisableDirectives: true, overrides: [ { @@ -36,6 +39,9 @@ module.exports = { parserOptions: { project: ['tsconfig.test.json'], }, + rules: { + '@typescript-eslint/no-explicit-any': 'off', + }, }, { files: ['scripts/**/*.ts'], diff --git a/dev-packages/.eslintrc.js b/dev-packages/.eslintrc.js new file mode 100644 index 000000000000..15dafc98d9db --- /dev/null +++ b/dev-packages/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + extends: ['../.eslintrc.js'], + rules: { + // tests often have just cause to do evil + '@typescript-eslint/no-explicit-any': 'off', + }, +}; diff --git a/dev-packages/browser-integration-tests/.eslintrc.js b/dev-packages/browser-integration-tests/.eslintrc.js index 8c07222e9a7c..6e8960a45a06 100644 --- a/dev-packages/browser-integration-tests/.eslintrc.js +++ b/dev-packages/browser-integration-tests/.eslintrc.js @@ -4,7 +4,7 @@ module.exports = { node: true, }, // todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project - extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'], + extends: ['../.eslintrc.js', 'plugin:regexp/recommended'], plugins: ['regexp'], ignorePatterns: [ 'suites/**/subject.js', diff --git a/dev-packages/bundler-tests/.eslintrc.js b/dev-packages/bundler-tests/.eslintrc.js index a65cf78e0b57..5c6808c0f73e 100644 --- a/dev-packages/bundler-tests/.eslintrc.js +++ b/dev-packages/bundler-tests/.eslintrc.js @@ -1,5 +1,5 @@ module.exports = { - extends: ['../../.eslintrc.js'], + extends: ['../.eslintrc.js'], parserOptions: { sourceType: 'module', }, diff --git a/dev-packages/clear-cache-gh-action/.eslintrc.cjs b/dev-packages/clear-cache-gh-action/.eslintrc.cjs index 9472d27555a3..9f5a866e852f 100644 --- a/dev-packages/clear-cache-gh-action/.eslintrc.cjs +++ b/dev-packages/clear-cache-gh-action/.eslintrc.cjs @@ -1,6 +1,6 @@ module.exports = { // todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project - extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'], + extends: ['../.eslintrc.js', 'plugin:regexp/recommended'], plugins: ['regexp'], parserOptions: { sourceType: 'module', diff --git a/dev-packages/cloudflare-integration-tests/.eslintrc.js b/dev-packages/cloudflare-integration-tests/.eslintrc.js index 5ce331e4074a..2cd3ff680383 100644 --- a/dev-packages/cloudflare-integration-tests/.eslintrc.js +++ b/dev-packages/cloudflare-integration-tests/.eslintrc.js @@ -3,7 +3,7 @@ module.exports = { node: true, }, // todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project - extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'], + extends: ['../.eslintrc.js', 'plugin:regexp/recommended'], plugins: ['regexp'], overrides: [ { diff --git a/dev-packages/cloudflare-integration-tests/suites/tracing/google-genai/mocks.ts b/dev-packages/cloudflare-integration-tests/suites/tracing/google-genai/mocks.ts index 22ccba15bc36..fc475234ef5c 100644 --- a/dev-packages/cloudflare-integration-tests/suites/tracing/google-genai/mocks.ts +++ b/dev-packages/cloudflare-integration-tests/suites/tracing/google-genai/mocks.ts @@ -3,7 +3,6 @@ import type { GoogleGenAIChat, GoogleGenAIClient, GoogleGenAIResponse } from '@s export class MockGoogleGenAI implements GoogleGenAIClient { public models: { generateContent: (...args: unknown[]) => Promise; - // eslint-disable-next-line @typescript-eslint/no-explicit-any generateContentStream: (...args: unknown[]) => Promise>; }; public chats: { diff --git a/dev-packages/e2e-tests/.eslintrc.js b/dev-packages/e2e-tests/.eslintrc.js index 9c0a56bca5f4..f285653c3e52 100644 --- a/dev-packages/e2e-tests/.eslintrc.js +++ b/dev-packages/e2e-tests/.eslintrc.js @@ -3,7 +3,7 @@ module.exports = { node: true, }, // todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project - extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'], + extends: ['../.eslintrc.js', 'plugin:regexp/recommended'], plugins: ['regexp'], ignorePatterns: ['test-applications/**', 'tmp/**'], parserOptions: { diff --git a/dev-packages/external-contributor-gh-action/.eslintrc.cjs b/dev-packages/external-contributor-gh-action/.eslintrc.cjs index 9472d27555a3..9f5a866e852f 100644 --- a/dev-packages/external-contributor-gh-action/.eslintrc.cjs +++ b/dev-packages/external-contributor-gh-action/.eslintrc.cjs @@ -1,6 +1,6 @@ module.exports = { // todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project - extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'], + extends: ['../.eslintrc.js', 'plugin:regexp/recommended'], plugins: ['regexp'], parserOptions: { sourceType: 'module', diff --git a/dev-packages/node-core-integration-tests/.eslintrc.js b/dev-packages/node-core-integration-tests/.eslintrc.js index e307575fe52e..ce21050cd142 100644 --- a/dev-packages/node-core-integration-tests/.eslintrc.js +++ b/dev-packages/node-core-integration-tests/.eslintrc.js @@ -3,7 +3,7 @@ module.exports = { node: true, }, // todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project - extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'], + extends: ['../.eslintrc.js', 'plugin:regexp/recommended'], plugins: ['regexp'], overrides: [ { diff --git a/dev-packages/node-integration-tests/.eslintrc.js b/dev-packages/node-integration-tests/.eslintrc.js index e307575fe52e..ce21050cd142 100644 --- a/dev-packages/node-integration-tests/.eslintrc.js +++ b/dev-packages/node-integration-tests/.eslintrc.js @@ -3,7 +3,7 @@ module.exports = { node: true, }, // todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project - extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'], + extends: ['../.eslintrc.js', 'plugin:regexp/recommended'], plugins: ['regexp'], overrides: [ { diff --git a/dev-packages/node-overhead-gh-action/.eslintrc.cjs b/dev-packages/node-overhead-gh-action/.eslintrc.cjs index a1c4f5968e46..3560c39da4eb 100644 --- a/dev-packages/node-overhead-gh-action/.eslintrc.cjs +++ b/dev-packages/node-overhead-gh-action/.eslintrc.cjs @@ -3,7 +3,7 @@ module.exports = { node: true, }, // todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project - extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'], + extends: ['../.eslintrc.js', 'plugin:regexp/recommended'], plugins: ['regexp'], overrides: [ { diff --git a/dev-packages/rollup-utils/.eslintrc.cjs b/dev-packages/rollup-utils/.eslintrc.cjs index f4a3ac1b8cb7..c44899e31665 100644 --- a/dev-packages/rollup-utils/.eslintrc.cjs +++ b/dev-packages/rollup-utils/.eslintrc.cjs @@ -1,6 +1,6 @@ module.exports = { // todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project - extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'], + extends: ['../.eslintrc.js', 'plugin:regexp/recommended'], plugins: ['regexp'], ignorePatterns: ['otelLoaderTemplate.js.tmpl'], sourceType: 'module', diff --git a/dev-packages/size-limit-gh-action/.eslintrc.cjs b/dev-packages/size-limit-gh-action/.eslintrc.cjs index fbc38a65db9c..ad9dd7b90cb4 100644 --- a/dev-packages/size-limit-gh-action/.eslintrc.cjs +++ b/dev-packages/size-limit-gh-action/.eslintrc.cjs @@ -1,6 +1,6 @@ module.exports = { // todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project - extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'], + extends: ['../.eslintrc.js', 'plugin:regexp/recommended'], plugins: ['regexp'], parserOptions: { sourceType: 'module', diff --git a/dev-packages/test-utils/.eslintrc.js b/dev-packages/test-utils/.eslintrc.js index 3be74e6c3f9d..d486b3046d17 100644 --- a/dev-packages/test-utils/.eslintrc.js +++ b/dev-packages/test-utils/.eslintrc.js @@ -3,6 +3,6 @@ module.exports = { node: true, }, // todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project - extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'], + extends: ['../.eslintrc.js', 'plugin:regexp/recommended'], plugins: ['regexp'], }; diff --git a/packages/aws-serverless/src/integration/instrumentation-aws-lambda/types.ts b/packages/aws-serverless/src/integration/instrumentation-aws-lambda/types.ts index 1b7603281ba0..f2503b134a2d 100644 --- a/packages/aws-serverless/src/integration/instrumentation-aws-lambda/types.ts +++ b/packages/aws-serverless/src/integration/instrumentation-aws-lambda/types.ts @@ -15,6 +15,7 @@ * limitations under the License. */ +/* eslint-disable @typescript-eslint/no-explicit-any */ import type { Context as OtelContext, Span } from '@opentelemetry/api'; import type { InstrumentationConfig } from '@opentelemetry/instrumentation'; import type { Context } from 'aws-lambda'; diff --git a/packages/cloudflare/src/durableobject.ts b/packages/cloudflare/src/durableobject.ts index db1da6a5d172..a0c042c6a755 100644 --- a/packages/cloudflare/src/durableobject.ts +++ b/packages/cloudflare/src/durableobject.ts @@ -28,7 +28,8 @@ type MethodWrapperOptions = { }; // eslint-disable-next-line @typescript-eslint/no-explicit-any -type OriginalMethod = (...args: any[]) => any; +type UncheckedMethod = (...args: any[]) => any; +type OriginalMethod = UncheckedMethod; function wrapMethodWithSentry( wrapperOptions: MethodWrapperOptions, @@ -269,8 +270,7 @@ export function instrumentDurableObjectWithSentry< // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any (obj as any)[method] = wrapMethodWithSentry( { options, context, spanName: method, spanOp: 'rpc' }, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - value as (...args: any[]) => any, + value as UncheckedMethod, ); } } @@ -332,7 +332,7 @@ function instrumentPrototype(target: T, methodsToInst } // Create a wrapper that gets context/options from the instance at runtime - const wrappedMethod = function (this: any, ...args: any[]): unknown { + const wrappedMethod = function (this: unknown, ...args: unknown[]): unknown { const thisWithSentry = this as { __SENTRY_CONTEXT__: DurableObjectState; __SENTRY_OPTIONS__: CloudflareOptions; @@ -342,7 +342,7 @@ function instrumentPrototype(target: T, methodsToInst if (!instanceOptions) { // Fallback to original method if no Sentry data found - return (originalMethod as (...args: any[]) => any).apply(this, args); + return (originalMethod as UncheckedMethod).apply(this, args); } // Use the existing wrapper but with instance-specific context/options @@ -353,12 +353,12 @@ function instrumentPrototype(target: T, methodsToInst spanName: methodName, spanOp: 'rpc', }, - originalMethod as (...args: any[]) => any, + originalMethod as UncheckedMethod, undefined, true, // noMark = true since we'll mark the prototype method ); - return (wrapper as (...args: any[]) => any).apply(this, args); + return wrapper.apply(this, args); }; markAsInstrumented(wrappedMethod); diff --git a/packages/core/src/integrations/supabase.ts b/packages/core/src/integrations/supabase.ts index 61005fdad805..1b6f24cc3136 100644 --- a/packages/core/src/integrations/supabase.ts +++ b/packages/core/src/integrations/supabase.ts @@ -1,6 +1,7 @@ // Based on Kamil Ogórek's work on: // https://github.com/supabase-community/sentry-integration-js +/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable max-lines */ import { addBreadcrumb } from '../breadcrumbs'; import { DEBUG_BUILD } from '../debug-build'; diff --git a/packages/core/src/types-hoist/breadcrumb.ts b/packages/core/src/types-hoist/breadcrumb.ts index 1c5bef4bc49a..391100a5a377 100644 --- a/packages/core/src/types-hoist/breadcrumb.ts +++ b/packages/core/src/types-hoist/breadcrumb.ts @@ -52,6 +52,7 @@ export interface Breadcrumb { * * @summary Arbitrary data associated with this breadcrumb. */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any data?: { [key: string]: any }; /** @@ -70,6 +71,7 @@ export interface Breadcrumb { /** JSDoc */ export interface BreadcrumbHint { + // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any; } @@ -90,6 +92,7 @@ export interface XhrBreadcrumbData { } export interface FetchBreadcrumbHint { + // eslint-disable-next-line @typescript-eslint/no-explicit-any input: any[]; data?: unknown; response?: unknown; diff --git a/packages/core/src/types-hoist/context.ts b/packages/core/src/types-hoist/context.ts index a3673f84a968..9e52ff9d6834 100644 --- a/packages/core/src/types-hoist/context.ts +++ b/packages/core/src/types-hoist/context.ts @@ -99,6 +99,7 @@ export interface ResponseContext extends Record { } export interface TraceContext extends Record { + // eslint-disable-next-line @typescript-eslint/no-explicit-any data?: { [key: string]: any }; op?: string; parent_span_id?: string; diff --git a/packages/core/src/types-hoist/error.ts b/packages/core/src/types-hoist/error.ts index d94becdbaf1f..df67cf898f41 100644 --- a/packages/core/src/types-hoist/error.ts +++ b/packages/core/src/types-hoist/error.ts @@ -2,5 +2,5 @@ * Just an Error object with arbitrary attributes attached to it. */ export interface ExtendedError extends Error { - [key: string]: any; + [key: string]: unknown; } diff --git a/packages/core/src/types-hoist/event.ts b/packages/core/src/types-hoist/event.ts index a042edad2cda..6b333bd2388e 100644 --- a/packages/core/src/types-hoist/event.ts +++ b/packages/core/src/types-hoist/event.ts @@ -83,6 +83,7 @@ export interface EventHint { syntheticException?: Error | null; originalException?: unknown; attachments?: Attachment[]; + // eslint-disable-next-line @typescript-eslint/no-explicit-any data?: any; integrations?: string[]; } diff --git a/packages/core/src/types-hoist/instrument.ts b/packages/core/src/types-hoist/instrument.ts index b067f6618558..7caab9e3dacf 100644 --- a/packages/core/src/types-hoist/instrument.ts +++ b/packages/core/src/types-hoist/instrument.ts @@ -47,6 +47,7 @@ interface SentryFetchData { } export interface HandlerDataFetch { + // eslint-disable-next-line @typescript-eslint/no-explicit-any args: any[]; fetchData: SentryFetchData; // This data is among other things dumped directly onto the fetch breadcrumb data startTimestamp: number; @@ -74,6 +75,7 @@ export interface HandlerDataDom { export interface HandlerDataConsole { level: ConsoleLevel; + // eslint-disable-next-line @typescript-eslint/no-explicit-any args: any[]; } diff --git a/packages/core/src/types-hoist/integration.ts b/packages/core/src/types-hoist/integration.ts index cc9e4bc580ce..120cb1acc884 100644 --- a/packages/core/src/types-hoist/integration.ts +++ b/packages/core/src/types-hoist/integration.ts @@ -47,4 +47,5 @@ export interface Integration { * An integration in function form. * This is expected to return an integration. */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any export type IntegrationFn = (...rest: any[]) => IntegrationType; diff --git a/packages/core/src/types-hoist/misc.ts b/packages/core/src/types-hoist/misc.ts index af9ed8fc6bd7..162e49b4b67f 100644 --- a/packages/core/src/types-hoist/misc.ts +++ b/packages/core/src/types-hoist/misc.ts @@ -4,7 +4,7 @@ import type { QueryParams } from './request'; * Data extracted from an incoming request to a node server */ export interface ExtractedNodeRequestData { - [key: string]: any; + [key: string]: unknown; /** Specific headers from the request */ headers?: { [key: string]: string }; diff --git a/packages/core/src/types-hoist/polymorphics.ts b/packages/core/src/types-hoist/polymorphics.ts index 88abf7770b2c..74ade60e2098 100644 --- a/packages/core/src/types-hoist/polymorphics.ts +++ b/packages/core/src/types-hoist/polymorphics.ts @@ -50,12 +50,14 @@ type NextjsRequest = NodeRequest & { [key: string]: string; }; query?: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any; }; }; type ExpressRequest = NodeRequest & { baseUrl?: string; + // eslint-disable-next-line @typescript-eslint/no-explicit-any body?: string | { [key: string]: any }; host?: string; hostname?: string; @@ -70,9 +72,11 @@ type ExpressRequest = NodeRequest & { ]; }; query?: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any; }; user?: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any; }; _reconstructedRoute?: string; diff --git a/packages/core/src/types-hoist/samplingcontext.ts b/packages/core/src/types-hoist/samplingcontext.ts index b0a52862870c..20b4de8b5125 100644 --- a/packages/core/src/types-hoist/samplingcontext.ts +++ b/packages/core/src/types-hoist/samplingcontext.ts @@ -6,7 +6,7 @@ import type { SpanAttributes } from './span'; * Context data passed by the user when starting a transaction, to be used by the tracesSampler method. */ export interface CustomSamplingContext { - [key: string]: any; + [key: string]: unknown; } /** diff --git a/packages/core/src/types-hoist/stackframe.ts b/packages/core/src/types-hoist/stackframe.ts index 4f99f1ba3595..fb5f64ff131a 100644 --- a/packages/core/src/types-hoist/stackframe.ts +++ b/packages/core/src/types-hoist/stackframe.ts @@ -13,7 +13,7 @@ export interface StackFrame { in_app?: boolean; instruction_addr?: string; addr_mode?: string; - vars?: { [key: string]: any }; + vars?: { [key: string]: unknown }; debug_id?: string; - module_metadata?: any; + module_metadata?: unknown; } diff --git a/packages/core/src/types-hoist/user.ts b/packages/core/src/types-hoist/user.ts index 801fb66202b1..cb849acdab43 100644 --- a/packages/core/src/types-hoist/user.ts +++ b/packages/core/src/types-hoist/user.ts @@ -2,7 +2,7 @@ * An interface describing a user of an application or a handled request. */ export interface User { - [key: string]: any; + [key: string]: unknown; id?: string | number; ip_address?: string | null; email?: string; diff --git a/packages/core/src/utils/aggregate-errors.ts b/packages/core/src/utils/aggregate-errors.ts index 16d100d60c09..1af9e1d6eebb 100644 --- a/packages/core/src/utils/aggregate-errors.ts +++ b/packages/core/src/utils/aggregate-errors.ts @@ -64,7 +64,7 @@ function aggregateExceptionsFromError( exceptionFromErrorImplementation, parser, limit, - error[key], + error[key] as ExtendedError, key, [newException, ...newExceptions], newException, @@ -85,7 +85,7 @@ function aggregateExceptionsFromError( exceptionFromErrorImplementation, parser, limit, - childError, + childError as ExtendedError, key, [newException, ...newExceptions], newException, diff --git a/packages/core/src/utils/is.ts b/packages/core/src/utils/is.ts index 9abfab910099..b07c86c7dbc5 100644 --- a/packages/core/src/utils/is.ts +++ b/packages/core/src/utils/is.ts @@ -180,7 +180,7 @@ export function isSyntheticEvent(wat: unknown): boolean { * @param base A constructor to be used in a check. * @returns A boolean representing the result. */ -export function isInstanceOf(wat: any, base: any): boolean { +export function isInstanceOf(wat: unknown, base: { new (...args: any[]): T }): wat is T { try { return wat instanceof base; } catch { diff --git a/packages/core/test/lib/utils/is.test.ts b/packages/core/test/lib/utils/is.test.ts index 092ffae2e3c3..726053e6f53d 100644 --- a/packages/core/test/lib/utils/is.test.ts +++ b/packages/core/test/lib/utils/is.test.ts @@ -107,15 +107,24 @@ describe('isInstanceOf()', () => { expect(isInstanceOf(new Date(), Date)).toEqual(true); // @ts-expect-error Foo implicity has any type, doesn't have constructor expect(isInstanceOf(new Foo(), Foo)).toEqual(true); - + // @ts-expect-error Should only allow constructors expect(isInstanceOf(new Error('wat'), Foo)).toEqual(false); expect(isInstanceOf(new Date('wat'), Error)).toEqual(false); + + // verify type inference + const d: unknown = new Date(); + const e: Date = isInstanceOf(d, Date) ? d : new Date(); + expect(e).toEqual(d); }); test('should not break with incorrect input', () => { + // @ts-expect-error Should only allow constructors expect(isInstanceOf(new Error('wat'), 1)).toEqual(false); + // @ts-expect-error Should only allow constructors expect(isInstanceOf(new Error('wat'), 'wat')).toEqual(false); + // @ts-expect-error Should only allow constructors expect(isInstanceOf(new Error('wat'), null)).toEqual(false); + // @ts-expect-error Should only allow constructors expect(isInstanceOf(new Error('wat'), undefined)).toEqual(false); }); }); diff --git a/packages/feedback/src/modal/integration.tsx b/packages/feedback/src/modal/integration.tsx index 0e3f8a637149..a921a32ad7be 100644 --- a/packages/feedback/src/modal/integration.tsx +++ b/packages/feedback/src/modal/integration.tsx @@ -69,8 +69,8 @@ export const feedbackModalIntegration = ((): FeedbackModalIntegration => { screenshotInput={screenshotInput} showName={options.showName || options.isNameRequired} showEmail={options.showEmail || options.isEmailRequired} - defaultName={(userKey && user?.[userKey.name]) || ''} - defaultEmail={(userKey && user?.[userKey.email]) || ''} + defaultName={String((userKey && user?.[userKey.name]) || '')} + defaultEmail={String((userKey && user?.[userKey.email]) || '')} onFormClose={() => { renderContent(false); options.onFormClose?.(); diff --git a/packages/nextjs/src/config/types.ts b/packages/nextjs/src/config/types.ts index c7472c08fc20..ecf8e272fe93 100644 --- a/packages/nextjs/src/config/types.ts +++ b/packages/nextjs/src/config/types.ts @@ -11,8 +11,8 @@ type NextRewrite = { }; interface WebpackPluginInstance { - [index: string]: any; - apply: (compiler: any) => void; + [index: string]: unknown; + apply: (compiler: unknown) => void; } export type NextConfigObject = { diff --git a/packages/node/src/integrations/tracing/fastify/types.ts b/packages/node/src/integrations/tracing/fastify/types.ts index e15c1c85324b..1bc426e58aad 100644 --- a/packages/node/src/integrations/tracing/fastify/types.ts +++ b/packages/node/src/integrations/tracing/fastify/types.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ export type HandlerOriginal = | ((request: FastifyRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => Promise) | ((request: FastifyRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => void); diff --git a/packages/node/src/integrations/tracing/fastify/v3/instrumentation.ts b/packages/node/src/integrations/tracing/fastify/v3/instrumentation.ts index 7b8035927a11..9921ba536ba4 100644 --- a/packages/node/src/integrations/tracing/fastify/v3/instrumentation.ts +++ b/packages/node/src/integrations/tracing/fastify/v3/instrumentation.ts @@ -1,4 +1,5 @@ // Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/407f61591ba69a39a6908264379d4d98a48dbec4/plugins/node/opentelemetry-instrumentation-fastify/src/instrumentation.ts +/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-this-alias */ /* eslint-disable jsdoc/require-jsdoc */ /* eslint-disable @typescript-eslint/explicit-function-return-type */ diff --git a/packages/node/src/integrations/tracing/fastify/v3/types.ts b/packages/node/src/integrations/tracing/fastify/v3/types.ts index b4c30a3dd36f..4d41a729f9d0 100644 --- a/packages/node/src/integrations/tracing/fastify/v3/types.ts +++ b/packages/node/src/integrations/tracing/fastify/v3/types.ts @@ -1,4 +1,5 @@ // Vendored from: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/407f61591ba69a39a6908264379d4d98a48dbec4/plugins/node/opentelemetry-instrumentation-fastify/src/types.ts +/* eslint-disable @typescript-eslint/no-explicit-any */ /* * Copyright The OpenTelemetry Authors * diff --git a/packages/node/src/integrations/tracing/fastify/v3/utils.ts b/packages/node/src/integrations/tracing/fastify/v3/utils.ts index 41f4a706b038..26f0014a67e1 100644 --- a/packages/node/src/integrations/tracing/fastify/v3/utils.ts +++ b/packages/node/src/integrations/tracing/fastify/v3/utils.ts @@ -3,6 +3,7 @@ /* eslint-disable @typescript-eslint/no-dynamic-delete */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/explicit-function-return-type */ +/* eslint-disable @typescript-eslint/no-explicit-any */ /* * Copyright The OpenTelemetry Authors * diff --git a/packages/node/src/integrations/tracing/firebase/otel/patches/firestore.ts b/packages/node/src/integrations/tracing/firebase/otel/patches/firestore.ts index 43cf61917e21..d23fd091ffac 100644 --- a/packages/node/src/integrations/tracing/firebase/otel/patches/firestore.ts +++ b/packages/node/src/integrations/tracing/firebase/otel/patches/firestore.ts @@ -38,7 +38,9 @@ import type { // Inline minimal types used from `shimmer` to avoid importing shimmer's types directly. // We only need the shape for `wrap` and `unwrap` used in this file. +// eslint-disable-next-line @typescript-eslint/no-explicit-any type ShimmerWrap = (target: any, name: string, wrapper: (...args: any[]) => any) => void; +// eslint-disable-next-line @typescript-eslint/no-explicit-any type ShimmerUnwrap = (target: any, name: string) => void; /** diff --git a/packages/node/src/integrations/tracing/firebase/otel/types.ts b/packages/node/src/integrations/tracing/firebase/otel/types.ts index ead830fa2c1a..4b94cbefe02c 100644 --- a/packages/node/src/integrations/tracing/firebase/otel/types.ts +++ b/packages/node/src/integrations/tracing/firebase/otel/types.ts @@ -1,5 +1,6 @@ import type { Span } from '@opentelemetry/api'; import type { InstrumentationConfig } from '@opentelemetry/instrumentation'; +/* eslint-disable @typescript-eslint/no-explicit-any */ // Inlined types from 'firebase/app' export interface FirebaseOptions { diff --git a/packages/node/src/integrations/tracing/postgresjs.ts b/packages/node/src/integrations/tracing/postgresjs.ts index 438a63c804c6..b0147feeac9e 100644 --- a/packages/node/src/integrations/tracing/postgresjs.ts +++ b/packages/node/src/integrations/tracing/postgresjs.ts @@ -1,4 +1,5 @@ // Instrumentation for https://github.com/porsager/postgres +/* eslint-disable @typescript-eslint/no-explicit-any */ import { context, trace } from '@opentelemetry/api'; import type { InstrumentationConfig } from '@opentelemetry/instrumentation'; import { diff --git a/packages/remix/src/utils/types.ts b/packages/remix/src/utils/types.ts index 9634678a05ce..46b44ce5afa9 100644 --- a/packages/remix/src/utils/types.ts +++ b/packages/remix/src/utils/types.ts @@ -1,4 +1,5 @@ -export type SentryMetaArgs any> = Parameters[0] & { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export type SentryMetaArgs any> = Parameters[0] & { data: { sentryTrace: string; sentryBaggage: string; diff --git a/packages/remix/src/vendor/instrumentation.ts b/packages/remix/src/vendor/instrumentation.ts index e42f6709c0c4..9da38fbd0e7a 100644 --- a/packages/remix/src/vendor/instrumentation.ts +++ b/packages/remix/src/vendor/instrumentation.ts @@ -1,5 +1,8 @@ /* eslint-disable deprecation/deprecation */ /* eslint-disable jsdoc/require-jsdoc */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable import/no-named-as-default-member */ +/* eslint-disable import/no-duplicates */ // Vendored and modified from: // https://github.com/justindsmith/opentelemetry-instrumentations-js/blob/3b1e8c3e566e5cc3389e9c28cafce6a5ebb39600/packages/instrumentation-remix/src/instrumentation.ts diff --git a/packages/replay-internal/rollup.npm.config.mjs b/packages/replay-internal/rollup.npm.config.mjs index 3d6e8fcf4dff..f45b4f21b72b 100644 --- a/packages/replay-internal/rollup.npm.config.mjs +++ b/packages/replay-internal/rollup.npm.config.mjs @@ -1,3 +1,4 @@ +/* eslint-disable import/no-named-as-default */ import nodeResolve from '@rollup/plugin-node-resolve'; import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils'; diff --git a/packages/replay-internal/src/types/rrweb.ts b/packages/replay-internal/src/types/rrweb.ts index 33f5e1b3bf7f..0d9a2d6065d9 100644 --- a/packages/replay-internal/src/types/rrweb.ts +++ b/packages/replay-internal/src/types/rrweb.ts @@ -69,7 +69,9 @@ export interface CanvasManagerOptions { type: string; quality: number; }>; + // eslint-disable-next-line @typescript-eslint/no-explicit-any mutationCb: (p: any) => void; win: typeof globalThis & Window; + // eslint-disable-next-line @typescript-eslint/no-explicit-any mirror: any; } diff --git a/packages/vercel-edge/src/vendored/async-local-storage-context-manager.ts b/packages/vercel-edge/src/vendored/async-local-storage-context-manager.ts index 257c6c27f041..f60a5aa265b2 100644 --- a/packages/vercel-edge/src/vendored/async-local-storage-context-manager.ts +++ b/packages/vercel-edge/src/vendored/async-local-storage-context-manager.ts @@ -24,6 +24,7 @@ /* eslint-disable @typescript-eslint/explicit-member-accessibility */ /* eslint-disable jsdoc/require-jsdoc */ +/* eslint-disable @typescript-eslint/no-explicit-any */ import type { Context } from '@opentelemetry/api'; import { ROOT_CONTEXT } from '@opentelemetry/api'; @@ -44,7 +45,7 @@ export class AsyncLocalStorageContextManager extends AbstractAsyncHooksContextMa constructor() { super(); - // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access const MaybeGlobalAsyncLocalStorageConstructor = (GLOBAL_OBJ as any).AsyncLocalStorage; if (!MaybeGlobalAsyncLocalStorageConstructor) { diff --git a/packages/vercel-edge/test/wintercg-fetch.test.ts b/packages/vercel-edge/test/wintercg-fetch.test.ts index a413cc7e93da..d430b46df831 100644 --- a/packages/vercel-edge/test/wintercg-fetch.test.ts +++ b/packages/vercel-edge/test/wintercg-fetch.test.ts @@ -1,6 +1,5 @@ import type { HandlerDataFetch, Integration } from '@sentry/core'; import * as sentryCore from '@sentry/core'; -import * as sentryUtils from '@sentry/core'; import { createStackParser } from '@sentry/core'; import { beforeEach, describe, expect, it, vi } from 'vitest'; import { VercelEdgeClient } from '../src/index'; @@ -12,7 +11,7 @@ class FakeClient extends VercelEdgeClient { } } -const addFetchInstrumentationHandlerSpy = vi.spyOn(sentryUtils, 'addFetchInstrumentationHandler'); +const addFetchInstrumentationHandlerSpy = vi.spyOn(sentryCore, 'addFetchInstrumentationHandler'); const instrumentFetchRequestSpy = vi.spyOn(sentryCore, 'instrumentFetchRequest'); const addBreadcrumbSpy = vi.spyOn(sentryCore, 'addBreadcrumb'); diff --git a/packages/vue/src/pinia.ts b/packages/vue/src/pinia.ts index f55be4d6602c..6ac46fae70a5 100644 --- a/packages/vue/src/pinia.ts +++ b/packages/vue/src/pinia.ts @@ -2,7 +2,7 @@ import { addBreadcrumb, addNonEnumerableProperty, getClient, getCurrentScope, ge import type { Ref } from 'vue'; // Inline Pinia types -type StateTree = Record; +type StateTree = Record; type PiniaPlugin = (context: { store: { $id: string; @@ -15,8 +15,8 @@ type PiniaPlugin = (context: { type SentryPiniaPluginOptions = { attachPiniaState: boolean; addBreadcrumbs: boolean; - actionTransformer: (action: string) => any; - stateTransformer: (state: Record) => any; + actionTransformer: (action: string) => unknown; + stateTransformer: (state: Record) => Record; }; const DEFAULT_PINIA_PLUGIN_OPTIONS: SentryPiniaPluginOptions = {