cloudflare / workers-types

TypeScript type definitions for authoring Cloudflare Workers.
BSD 3-Clause "New" or "Revised" License
359 stars 89 forks source link

Incorrect D1 types #289

Closed probablykasper closed 1 year ago

probablykasper commented 2 years ago

There seems to be a lot of incorrect types for D1

Two examples (I'm sure there are others):

mmitou commented 1 year ago

Hi,

The D1 Client API document states the following

The methods stmt.run(), stmt.all() and db.batch() return an object that contains the results (if applicable), the success status, and a meta object with the internal duration of the operation in milliseconds.

The D1Result type provided by the workers-types library in version 3.18.0 does not seem to have "success" and "meta" properties.

declare type D1Result<T = unknown> = {
  results?: T[];
  lastRowId: number | null;
  changes: number;
  duration: number;
  error?: string;
};

It seems that the D1Result types defined in the "override" directory in the workers-types repository have not been merged.

Also, when I actually run the query, the return value of the query has the "success" property but not the "meta" property, and instead has the "duration" property.

I am contacting you just in case.

mrbbot commented 1 year ago

Hey! This has been fixed in @cloudflare/workers-types@4. 👍