Skip to content

Commit 596ece2

Browse files
authored
fix(types): add explicit types for composables & remove baseUrl from tsconfig (#404)
1 parent 8c479bc commit 596ece2

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

src/module.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,15 @@ export default defineNuxtModule<ModuleOptions>({
203203
addTemplate({
204204
filename: 'types/supabase-database.d.ts',
205205
getContents: async () => {
206-
if (!!options.types && fs.existsSync(await resolvePath(options.types))) {
207-
return `export * from '${await resolvePath(options.types)}'`
206+
if (options.types) {
207+
// resolvePath is used to minify user input error.
208+
const path = await resolvePath(options.types)
209+
const basePath = await resolvePath('~~') // ~~ should be the base path in a nuxt project.
210+
211+
if (fs.existsSync(path)) {
212+
// we are replacing the basePath with ../.. to move back to the root (~~) directory.
213+
return `export * from '${path.replace(basePath, '../..')}'`
214+
}
208215
}
209216

210217
return `export type Database = unknown`

src/runtime/composables/useSupabaseClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import type { SupabaseClient } from '@supabase/supabase-js'
22
import { useNuxtApp } from '#imports'
33
import type { Database } from '#build/types/supabase-database'
44

5-
export const useSupabaseClient = <T = Database>() => {
5+
export const useSupabaseClient: <T = Database>() => SupabaseClient<T> = <T = Database>() => {
66
return useNuxtApp().$supabase?.client as SupabaseClient<T>
77
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { Session } from '@supabase/supabase-js'
2-
import { useState } from '#imports'
2+
import { useState, type Ref } from '#imports'
33

44
/**
55
* Reactive `Session` state from Supabase. This is initialized in both client and server plugin
66
* and, on the client, also updated through `onAuthStateChange` events.
77
*/
8-
export const useSupabaseSession = () => useState<Session | null>('supabase_session', () => null)
8+
export const useSupabaseSession = (): Ref<Session> => useState<Session | null>('supabase_session', () => null)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { User } from '@supabase/supabase-js'
2-
import { useState } from '#imports'
2+
import { useState, type Ref } from '#imports'
33

44
/**
55
* Reactive `User` state from Supabase. This is initialized in both client and server plugin
66
* and, on the client, also updated through `onAuthStateChange` events.
77
*/
8-
export const useSupabaseUser = () => useState<User | null>('supabase_user', () => null)
8+
export const useSupabaseUser = (): Ref<User> => useState<User | null>('supabase_user', () => null)

tsconfig.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
"extends": "./.nuxt/tsconfig.json",
33
"compilerOptions": {
44
"strictNullChecks": false,
5-
"baseUrl": "src"
65
}
76
}
8-

0 commit comments

Comments
 (0)