Repository navigation
fix(misc): reduce any usage across packages - #2268
Merged
Merged
Conversation
@supabase/auth-js
@supabase/functions-js
@supabase/postgrest-js
@supabase/realtime-js
@supabase/storage-js
@supabase/supabase-js
commit: |
o-santi
suggested changes
Apr 22, 2026
mandarini
force-pushed
the
feat/reduce-any
branch
from
April 22, 2026 14:20
8cd4123 to
7af18d8
Compare
mandarini
force-pushed
the
feat/reduce-any
branch
from
April 28, 2026 10:17
af0d07d to
5d234ab
Compare
mandarini
force-pushed
the
feat/reduce-any
branch
from
April 29, 2026 14:11
5d234ab to
18c0c4e
Compare
o-santi
approved these changes
Apr 29, 2026
This was referenced May 11, 2026
This was referenced May 13, 2026
This was referenced May 13, 2026
This was referenced May 14, 2026
This was referenced May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace ~50 explicit
anyannotations withunknownand proper type narrowing in internal code. Highest-value change: auth-js xform/fetch chain now takesunknownat the JSON boundary, preventing bugs like the signedUrl typo (#2254) from silently passing type checks.e: any→ewith instanceof narrowingany→unknownin auth-js and storage-jsdata: any→data: unknown(internal only)No breaking changes, all modifications are internal.
Why
unknownremains in some placesSome
unknowns here are deliberate. They fall into a few categories where tightening would either be incorrect or carry a real cost:catch (e)— TypeScript enforces this. WithuseUnknownInCatchVariables(on understrict: true),catch (e: Error)is a compile error (TS1196). JavaScript allowsthrow <any value>— including strings, numbers, andnullfrom third-party code we call into — so the catch binding genuinely cannot be narrower thanunknown. Narrowing happens inside the block.errors: unknown[]collected from third-party callbacks (e.g._notifyAllSubscribers) — values come from user-suppliedonAuthStateChangecallbacks, which can throw anything. Downstream uses are onlyconsole.error(...)andthrow, both of which accept any value. Tightening toError[]would either lie about the type or require wrapping non-Errors, which loses fidelity for consumers throwing custom error classes.Runtime-detection globals (
WebSocketPair?: unknown,EdgeRuntime?: unknowninwebsocket-factory.ts) — used only for existence checks (typeof !== 'undefined').EdgeRuntimein particular isn't standardized across edge runtimes (different shapes in Vercel Edge, Next.js Edge, polyfills). Typing it would be claiming knowledge that doesn't hold cross-runtime;unknownenforces existence-check-only access.Why some
anys are still in the call chainJSON.parseandResponse.json()returnany— these are typedanyin TypeScript's standard library, not by us. To eliminateanyend-to-end here we'd need a runtime schema validator (zod / valibot / hand-rolled guards) at every response boundary. That's a non-trivial bundle/perf cost for an SDK shipped to bundle-sensitive runtimes (RN, edge, browsers), so the SDK leans on localized type assertions at the boundary instead.User-extensible payloads —
user_metadata,app_metadata, OAuth provider passthrough fields, PostgREST row shapes, Realtime broadcast payloads. The shape is defined by the consumer's application or by external services, not by Supabase. Where applicable these are typed via generics orRecord<string, unknown>; the remaining[key: string]: anyindex signatures (e.g. onSession,User) preserve ergonomics for fields the server may add (token_type,provider_token, etc.) without forcing every caller to narrow.What this PR does not do
anyfromJSON.parse/Response.json(), but out of scope here.[key: string]: anyindex signatures onUser/Sessiontounknown— would force narrowing on every read of provider passthrough fields. Deliberate trade-off, not an oversight.