Utilizing TypeScript Types for Supabase Integration

I am attempting to incorporate Supabase typescript types into my Next.js project, however, I encounter the error

Expected 0 type arguments, but received 1.

I'm following the instructions outlined in this documentation. Although I've successfully generated the types, I'm unable to implement them in my application.

Whenever I try to utilize the following code:

import { createClient } from "@/utils/supabase/server";
import { Database } from "@/types/supabase";

export async function myFunction() {
  const supabase = createClient<Database>();
}

The <Database> component triggers this error message:

Expected 0 type arguments, but received 1.
. If I remove <Database>, the error disappears, but I lose the benefits of type safety.

Answer №1

Give this a try:

import { Database } from '@/types/supabase'
import { createServerClient, type CookieOptions } from '@supabase/ssr'
import { cookies } from 'next/headers'

export const initializeClient = () => {
  const cookieStore = cookies()
  return createServerClient<Database>(
    process.env.SUPABASE_URL!,
    {
      cookies: {
        get(name: string) {
          return cookieStore.get(name)?.value
        },
        set(name: string, value: string, options: CookieOptions) {
          try {
            cookieStore.set({ name, value, ...options })
          } catch (error) {
            // The `set` method was called from a Server Component.
            // This can be ignored if you have middleware refreshing
            // user sessions.
          }
        },
        remove(name: string, options: CookieOptions) {
          try {
            cookieStore.set({ name, value: '', ...options })
          } catch (error) {
            // The `delete` method was called from a Server Component.
            // This can be ignored if you have middleware refreshing
            // user sessions.
          }
        },
      },
    }
  )
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Angular 4 with Ahead-Of-Time compilation in combination with Electron, as well as

I am new to Angular/Typescript and currently developing a cross-platform Desktop application with Electron and Angular 4. My current challenge involves using a Service in different components, but I need this service to be loaded from a separate file based ...

What is the method to acquire the firestore reference type in TypeScript?

Here is the code I am working with: import { DocumentReference } from '@firebase/firestore-types' export type Recipe = { author: string title: string ingredients: { quantity: number ingredient: DocumentReference["path"] ...

Encountered an error saying 'TextEncoder is not defined' when running Jest in Next.js version 14

I am currently working on testing some API call methods using Jest in a Next.js 14 environment. Below is my jest.config.js file: const nextJest = require("next/jest"); /** @type {import('jest').Config} */ const createJestConfig = next ...

Is there a way to renew a token when utilizing msal-node for Microsoft Integration?

Currently, I am utilizing the @azure/msal library in combination with Microsoft Graph APIs within a Confidential Client Application. After successfully configuring the initial flow and obtaining the access token through cca.acquireTokenByCode(), I have enc ...

Employee plus Concave Authentication

After incorporating a module that uses Convex into my Clerk authentication application, everything seemed to work smoothly. However, I encountered an issue when attempting to refresh the page after logging into the new module. Suddenly, I received an error ...

Error message: "Unidentified variable in the code snippet from MUIv5 sample."

Achieving the Objective To implement a drawer sidebar in MUI5 that can be toggled open and closed by the user, I am exploring the documentation for the Drawer component as well as referencing an example. Encountering an Issue Upon copying the code from ...

In the case of explicit object keys and string types, TypeScript does not narrow types

My current setup is as follows: export const PRISMA_TYPES_TO_TS = { 'Int': 'number', 'BigInt': 'number', 'Decimal': 'number', 'Float': 'number', 'String&apo ...

The function Router.push("/") is not functioning as expected when called within the pages/index.js file

Currently, I'm utilizing the Next JS next-auth/react library and aiming to direct authenticated users straight to the dashboard. Here's a snippet from my index.js file: import { useRouter } from "next/router"; import Link from "nex ...

Creating two number-like types in TypeScript that are incompatible with each other can be achieved by defining two

I've been grappling with the challenge of establishing two number-like/integer types in TypeScript that are mutually incompatible. For instance, consider the following code snippet where height and weight are both represented as number-like types. Ho ...

The issue of Next.js 13 failing to render on the browser has left users

I have encountered an issue while setting up a Next.js 13 Application. My React component is not displaying on the browser even though the global.css styles are rendering properly. I attempted to solve the problem by switching to a different browser, but u ...

A guide on creating tagged strings by parsing JSON data

I am currently working with next.js. In my json file, there is a string: { "title":"Just a text with <b>accent</b> inside", } I am trying to retrieve this string and return a modified version with the <b> tag includ ...

Invoke a function within an Angular component that is passed in as a parameter

Is it possible to invoke a function using a string in JavaScript? I have a scenario where I receive a string as the function name, and I need to call and run that function. However, my current code is not working as expected. Below is the code snippet I ...

Exploring through objects extensively and expanding all their values within Angular

I am in need of searching for a specific value within an object graph. Once this value is found, I want to set the 'expanded' property to true on that particular object, as well as on all containing objects up the object graph. For example, give ...

Use a loop to assign numbers to elements in an array based on a specific condition using JavaScript

Hello, I'm in the process of creating a looping pattern based on the conditions of the array object key. If the 'o' contains 't', the index will start from the 'n' starting point in the object, otherwise, the numbering wi ...

What is the process for incorporating a new page from a NextJS application into an AWS Amplify project?

I created a brand new page in src/pages/foo.tsx for my NextJS application Upon testing, I can successfully view the page at http://localhost:3000/foo However, after deploying to my Amplify app, the page refuses to load I've made efforts to update t ...

Querying data conditionally with Angular rxjs

I have a json file that contains multiple arrays structured like this: { A[] B[] C[] ... } This is the query I am using: myFunction():void{ this.apiService.getData() .pipe( map((response: any) => response.A), // to access to the &ap ...

Creating an endless scrolling feature with Ionic 3

My tech stack includes symfony3 and FosRestBundle for the backend, and Ionic 3 for the frontend development. While attempting to implement an InfiniteScroll feature following the Ionic documentation, I encountered an issue where only the loading text and ...

Leverage the JSON Web Token module within a Chrome extension

Currently in the process of developing a chrome extension but encountering an issue with loading the json web token node module in my Node.js setup. background-script.ts import jwt from 'jsonwebtoken'; // import * as jwt from '../node_mod ...

What is the best approach to limit the return type of a function in JSX?

Is it possible to create a function where the return type should be a specific JSX type? For instance: const setHosting : <GitlabLogo> | <GithubLogo> = (h: Hosting) => ??? In this case, the return type must either be <GitlabLogo> or ...

Discover the art of customizing child elements using vanilla extract!

I recently started using vanilla extract to add styles to a NextJS application. Is there a way to style child elements within the parent element without having to create another class? My React component has a structure like this: <ul className={style ...