planetscale / database-js

A Fetch API-compatible PlanetScale database driver
https://planetscale.com/docs/tutorials/planetscale-serverless-driver
Apache License 2.0
1.17k stars 35 forks source link

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

Closed reconbot closed 2 years ago

reconbot commented 2 years ago
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.

iheanyi commented 2 years ago

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!

iheanyi commented 2 years ago

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