udacity / cloudflare-typescript-workers

Types and mocks for building a tested Typescript Cloudflare Worker, generates three NPM packages
Apache License 2.0
139 stars 12 forks source link

KV Namespace list method signature confusion #27

Open adamjakab opened 3 years ago

adamjakab commented 3 years ago

https://github.com/udacity/cloudflare-typescript-workers/blob/57171c327149e48e85e1ad26cfe6fc4c485fa68f/packages/types-cloudflare-worker/src/global.ts#L668

The issue is with the list method signature (which is actually correct in the docblock above it). NAMESPACE.list({prefix?: string, limit?: number, cursor?: string})

If I call the list method like this: KVNAMESPACE.list('my_prefix').then((mylist) => {... then it compiles but during execution it thorows the following error: TypeError: Failed to execute 'list' on 'KvNamespace': parameter 1 is not of type 'ListOptions'.

If I call the list method like this: KVNAMESPACE.list({prefix: 'my_prefix'}).then((mylist) => {... then my code won't compile becasue I get: Error:(35, 25) TS2345: Argument of type '{ prefix: string; }' is not assignable to parameter of type 'string'.

only if i do:

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
KVNAMESPACE.list({ prefix: prefix }).then((mylist) => {...

then it will run.

marcelduin commented 3 years ago

I have the same issue.

Changing the list type definition on R668 of the above reference to a single any argument makes it work. But of course it's better to type the argument.