cloudflare / workers-types

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

Fix return type of D1PreparedStatement.all #285

Closed sdnts closed 2 years ago

sdnts commented 2 years ago

D1Result's generic parameter expects the type of a single item.

The type of result in the code below is D1Result<User[]>

type User = { id: string }
const result = ctx.d1.prepare("SELECT * FROM users").all<User>()

This means that the type of result.results actually ends up being User[][] instead of User[].

changeset-bot[bot] commented 2 years ago

🦋 Changeset detected

Latest commit: 0078f5be4dc8cf89e723726f9ebd0cbdac70bfd8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------------------------- | ----- | | @cloudflare/workers-types | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

sdnts commented 2 years ago

cc @mrbbot