Skip to content

feat: Avoid usage of any#17041

Open
mydea wants to merge 3 commits intodevelopfrom
fn/avoid-any
Open

feat: Avoid usage of any#17041
mydea wants to merge 3 commits intodevelopfrom
fn/avoid-any

Conversation

@mydea
Copy link
Member

@mydea mydea commented Jul 16, 2025

This makes the lint rule error, instead of warn, and gets rid of some more any usage. Some of that may technically be breaking because the types can be exposed, but this should be very unlikely to affect any users.

In a future version of eslint, this is on by default, but IMHO it makes sense for us anyhow - any should only be used when absolutely necessary and when we make a conscious choice to do so.

@mydea mydea requested review from AbhiPrasad and Lms24 July 16, 2025 13:28
@mydea mydea self-assigned this Jul 16, 2025
@mydea mydea requested review from a team as code owners July 16, 2025 13:28
@github-actions
Copy link
Contributor

github-actions bot commented Jul 16, 2025

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 23.76 kB -0.01% -1 B 🔽
@sentry/browser - with treeshaking flags 22.34 kB -0.02% -3 B 🔽
@sentry/browser (incl. Tracing) 39.41 kB -0.01% -3 B 🔽
@sentry/browser (incl. Tracing, Replay) 77.5 kB -0.03% -17 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.37 kB -0.03% -17 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 82.21 kB -0.03% -18 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 94.35 kB -0.01% -3 B 🔽
@sentry/browser (incl. Feedback) 40.46 kB +0.03% +11 B 🔺
@sentry/browser (incl. sendFeedback) 28.44 kB -0.02% -3 B 🔽
@sentry/browser (incl. FeedbackAsync) 33.34 kB -0.01% -2 B 🔽
@sentry/react 25.5 kB -0.01% -1 B 🔽
@sentry/react (incl. Tracing) 41.38 kB -0.02% -6 B 🔽
@sentry/vue 28.19 kB -0.01% -2 B 🔽
@sentry/vue (incl. Tracing) 41.21 kB -0.01% -4 B 🔽
@sentry/svelte 23.79 kB -0.01% -1 B 🔽
CDN Bundle 25.28 kB +0.01% +1 B 🔺
CDN Bundle (incl. Tracing) 39.28 kB - -
CDN Bundle (incl. Tracing, Replay) 75.38 kB -0.02% -10 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 80.82 kB -0.01% -6 B 🔽
CDN Bundle - uncompressed 73.86 kB +0.01% +4 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 116.3 kB +0.01% +4 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 230.53 kB -0.01% -7 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 243.34 kB -0.01% -7 B 🔽
@sentry/nextjs (client) 43.43 kB -0.02% -7 B 🔽
@sentry/sveltekit (client) 39.84 kB -0.01% -3 B 🔽
@sentry/node-core 47.48 kB +0.01% +1 B 🔺
@sentry/node 144.13 kB +0.01% +9 B 🔺
@sentry/node - without tracing 91.58 kB +0.01% +5 B 🔺
@sentry/aws-serverless 103.04 kB +0.01% +6 B 🔺

View base workflow run

@mydea mydea force-pushed the fn/avoid-any branch 2 times, most recently from ead56db to f0881c5 Compare July 18, 2025 06:39
@mydea mydea enabled auto-merge (squash) July 18, 2025 06:39
@mydea mydea force-pushed the fn/avoid-any branch 2 times, most recently from 6b8ef0c to 142d072 Compare July 25, 2025 12:13
mydea added 3 commits January 20, 2026 10:26
This makes the lint rule error, instead of warn, and gets rid of some more any usage.
Some of that may technically be breaking because the types can be exposed, but this should be very unlikely to affect any users.
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is definitely a change we should make but unfortunately, most of the interface changes from core are publicly exported. Some of the keys I think would be fine but others are unfortunately used (e.g. EventHint, CustomSamplingContext, etc). So we can leave this PR open until v11. Additionally, we can extract some of the actually internal changes and merge them in now.

EDIT: I'm not sure why I approved this in August. Maybe we talked about this offline and decided it's fine at the time 🤔 I'd rather avoid this breakage though for now, given v11 isn't too far away.

Comment on lines +57 to +58
email: keyof User;
name: keyof User;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: Unfortunately, I'm afraid this is a breaking change, given that previously any string value could be added here. Fully agree that we should type it as keyof User for much improved type safety though in the next major.

// TODO: fix in v11, convert any to unknown
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
[key: string]: unknown;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: technically this is breaking, too, since we also export the type from Core as well as from @sentry/types. Given that this is internal stuff and types is deprecated and to be removed in v11 (#18256) I'm fine with doing this now.

attachments?: Attachment[];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data?: any;
data?: unknown;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: breaking :(

export interface HandlerDataFetch {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
args: any[];
args: unknown[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: breaking :(

level: ConsoleLevel;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
args: any[];
args: unknown[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: breaking :(

// TODO: fix in v11, convert any to unknown
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
[key: string]: unknown;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: breaking :(

@andreiborza andreiborza added this to the 11.0.0 milestone Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants