planetscale/database-js

fetch config types not compatible with node-fetch v2 or undici

reconbot opened this issue · 2 comments

import { connect } from '@planetscale/database'
import { fetch } from 'undici'

export const connection = connect({
  url: process.env.DATABASE_URL,
  fetch,
})

Comes with a type error

Type '(input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>' is not assignable to type '(input: string, init?: ReqInit | undefined) => Promise<Pick<Response, "ok" | "json" | "status" | "statusText" | "text">>'.
  Types of parameters 'init' and 'init' are incompatible.
    Type 'ReqInit | undefined' is not assignable to type 'RequestInit | undefined'.
      Type 'ReqInit' is not assignable to type 'RequestInit | undefined'.
        Type 'ReqInit' is not assignable to type 'RequestInit'.
          Types of property 'headers' are incompatible.
            Type 'HeadersInit | undefined' is not assignable to type 'import("/Users/wizard/src/telley/telley-api/node_modules/.pnpm/undici@5.9.1/node_modules/undici/types/fetch").HeadersInit | undefined'.
              Type 'Headers' is not assignable to type 'HeadersInit | undefined'.
                Type 'Headers' is missing the following properties from type 'Headers': keys, values, entries, [Symbol.iterator]ts(2322)
index.d.ts(34, 5): The expected type comes from property 'fetch' which is declared here on type 'Config'

A very similar error comes with the node-fetch v2 types.

Thanks for reporting this! We're gonna take a look at this and get this fixed up, appreciate you taking the time to report this!

Could we get more information what version of each package you're using? And what version of Node?