Repository navigation
fix(misc): widen enum-like unions with (string & {}) for forward compat - #2300
Merged
Merged
Conversation
@supabase/auth-js
@supabase/functions-js
@supabase/postgrest-js
@supabase/realtime-js
@supabase/storage-js
@supabase/supabase-js
commit: |
mandarini
marked this pull request as ready for review
April 28, 2026 11:37
mandarini
marked this pull request as draft
April 28, 2026 11:38
mandarini
marked this pull request as ready for review
April 28, 2026 11:38
grdsdev
approved these changes
Apr 28, 2026
This was referenced May 11, 2026
This was referenced May 13, 2026
This was referenced May 13, 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.
Description
Adds
| (string & {})to closed string unions across all six packages so consumers can forward-compat against new server-supported values (or new client-side states) without losing literal-string autocomplete. Type-only change; no runtime behavior change.The
(string & {})trick is used instead of plain| stringbecause'a' | stringcollapses to juststringin TypeScript and loses the literal hints. The intersection prevents that collapse, so editors keep suggesting the known literals while the type also accepts arbitrary strings.What changed?
Widened the following types:
src/lib/types.ts,src/lib/webauthn.dom.ts):AuthFlowType,MobileOtpType,EmailOtpType,AuthenticatorAssuranceLevelsJwtHeader.alg,JWK.ktyOAuthClientGrantType,OAuthClientType,OAuthClientRegistrationType,CustomProviderTypeCredentialDeviceType,PublicKeyCredentialHint,AuthenticatorAttachmentgetAlgorithm()parameter widened to matchJwtHeader.alg(runtime already throws on unknown values viadefault:)RealtimeChannelSendResponse(src/RealtimeChannel.ts)LogLevel,RealtimeRemoveChannelResponse,HeartbeatStatus(src/RealtimeClient.ts)ConnectionState(src/lib/constants.ts)src/lib/types.ts):BucketType,VectorDataType,DistanceMetriccountparameter (acrossselect/insert/upsert/update/deleteinPostgrestQueryBuilder.tsandrpcinPostgrestClient.ts), and theformatparameter inPostgrestTransformBuilder.tssrc/edge-runtime.d.ts):BeforeunloadReasonsrc/SupabaseClient.ts):removeChannel/removeAllChannelsreturn types now reuse the (already widened)RealtimeRemoveChannelResponsefrom realtime-js instead of inlining the literal unionSkipped intentionally
type: 'create' | 'request') — these are discriminated-union tags used for narrowing the response shape, so widening them would defeat the purpose.AggregateFunction('count' | 'sum' | 'avg' | 'min' | 'max') — used as a token in template-literal type parsing of select queries; widening it would break the type-safe query parser.Both are tracked as deliberate exclusions for future review.
Why was this change needed?
Server-decoded enums and forward-looking parameters should not be exhaustive in the SDK types. When the server adds a new value (a new OTP channel, a new heartbeat status, a new bucket type, a new
countmode, etc.), consumers should be able to use it without waiting for an SDK release or resorting toas any. Keeping the literals as autocomplete hints preserves DX.Screenshots/Examples
Breaking changes
Type-only widening at the runtime level, and patch-level safe in practice for TypeScript consumers. Two narrow theoretical edge cases:
switch (x) { default: const _: never = x }over one of the widened unions will fail (theneverno longer holds).const r: 'ok' | 'timed out' | 'error' = await ch.send(...)errors.Both patterns are rare; standard usage (
if (r === 'ok'), switches with a regulardefaultbranch, untyped consumption) is unaffected.Checklist
<type>(<scope>): <description>npx nx formatto ensure consistent code formattingAdditional notes
Session,User,JwtHeader,JWK,RequiredClaims, Realtime payloads,PostgrestResponse*,FunctionsResponse*,FileMetadata, plus newer OAuth/MFA/Vector/SearchV2 shapes). That work is technically breaking for strict-mode TS consumers and is being kept out of this PR so the widening can land cleanly as a patch.nx test:types postgrest-jspasses (26/26).