Few TypeScript issue with a Nuxt3 app I'm trying to build, not sure how to fix them correctly..

https://github.com/callum-laing/daily-push First issue is session.value not acception "Session | null" to type "null", not sure how I fix that? LLM's suggest
js const session = ref<Session | null>(null);
js const session = ref<Session | null>(null);
but I'm not sure I trust that as it looks... odd.. Second issue is "any[]" not being able to assign to "never[]"
GitHub
GitHub - callum-laing/daily-push: Personal blog for me to publicly ...
Personal blog for me to publicly share my coding journey with the world. - callum-laing/daily-push
No description
1 Reply
CDL
CDLOP3mo ago
nevermind, both fixed. google to the rescue.
<script setup lang="ts">
import type { Session } from '@supabase/supabase-js';

const supabase = useNuxtApp().$supabase;
const session = ref<Session | null>(null);

onMounted(async () => {
const { data } = await supabase.auth.getSession();
session.value = data.session;
});
</script>
<script setup lang="ts">
import type { Session } from '@supabase/supabase-js';

const supabase = useNuxtApp().$supabase;
const session = ref<Session | null>(null);

onMounted(async () => {
const { data } = await supabase.auth.getSession();
session.value = data.session;
});
</script>
and the other fix was TS not liking an empty array ref, so it needed an explicit type.
interface Post {
id: number | string;
title: string;
date: string;
notes: string;
}

const supabase = useNuxtApp().$supabase;
const posts = ref<Post[]>([]);
interface Post {
id: number | string;
title: string;
date: string;
notes: string;
}

const supabase = useNuxtApp().$supabase;
const posts = ref<Post[]>([]);

Did you find this page helpful?