Skip to content

Commit 52bf37f

Browse files
authored
ref: Update applySettingDefaults typings to use accurate return type (#1046)
1 parent 912f13e commit 52bf37f

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/SupabaseClient.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,20 @@ export default class SupabaseClient<
9292

9393
const settings = applySettingDefaults(options ?? {}, DEFAULTS)
9494

95-
this.storageKey = settings.auth?.storageKey ?? ''
96-
this.headers = settings.global?.headers ?? {}
95+
this.storageKey = settings.auth.storageKey ?? ''
96+
this.headers = settings.global.headers ?? {}
9797

9898
this.auth = this._initSupabaseAuthClient(
9999
settings.auth ?? {},
100100
this.headers,
101-
settings.global?.fetch
101+
settings.global.fetch
102102
)
103-
this.fetch = fetchWithAuth(supabaseKey, this._getAccessToken.bind(this), settings.global?.fetch)
103+
this.fetch = fetchWithAuth(supabaseKey, this._getAccessToken.bind(this), settings.global.fetch)
104104

105105
this.realtime = this._initRealtimeClient({ headers: this.headers, ...settings.realtime })
106106
this.rest = new PostgrestClient(`${_supabaseUrl}/rest/v1`, {
107107
headers: this.headers,
108-
schema: settings.db?.schema,
108+
schema: settings.db.schema,
109109
fetch: this.fetch,
110110
})
111111

src/lib/helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function applySettingDefaults<
2323
>(
2424
options: SupabaseClientOptions<SchemaName>,
2525
defaults: SupabaseClientOptions<any>
26-
): SupabaseClientOptions<SchemaName> {
26+
): Required<SupabaseClientOptions<SchemaName>> {
2727
const {
2828
db: dbOptions,
2929
auth: authOptions,

test/helpers.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ test('override setting defaults', async () => {
3333
},
3434
}
3535
let settings = helpers.applySettingDefaults(options, defaults)
36-
expect(settings?.auth?.autoRefreshToken).toBe(autoRefreshOption)
36+
expect(settings.auth.autoRefreshToken).toBe(autoRefreshOption)
3737
// Existing default properties should not be overwritten
38-
expect(settings?.auth?.persistSession).not.toBeNull()
39-
expect(settings?.global?.headers).toBe(DEFAULT_HEADERS)
38+
expect(settings.auth.persistSession).not.toBeNull()
39+
expect(settings.global.headers).toBe(DEFAULT_HEADERS)
4040
// Existing property values should remain constant
41-
expect(settings?.db?.schema).toBe(defaults.db.schema)
41+
expect(settings.db.schema).toBe(defaults.db.schema)
4242
})

0 commit comments

Comments
 (0)