workers-types icon indicating copy to clipboard operation
workers-types copied to clipboard

`KVNamespaceListResult` more specific types

Open DaniFoldi opened this issue 1 year ago • 0 comments

The two possibilities of

  • the listing being complete, list_complete: true and cursor is an empty string, or undefined (not tested)
  • there are more elements to be returned, list_complete: false and cursor is a string

With a union type of these two, TS compiler would know which case we are in, if we check list_complete, so cursor wouldn't have to be rechecked.

Docs: https://developers.cloudflare.com/workers/runtime-apis/kv/#pagination

Interface definition: https://github.com/cloudflare/workers-types/blob/38b7e0fba83f01654a00b0d805cd01211a419f3d/overrides/kv.d.ts#L17-L21

DaniFoldi avatar Jul 25 '22 12:07 DaniFoldi