cloudflare / worker-typescript-template

ʕ •́؈•̀) TypeScript template for Cloudflare Workers
Apache License 2.0
431 stars 95 forks source link

Using KV variables #47

Closed akshaybabloo closed 3 years ago

akshaybabloo commented 3 years ago

Using KV variables, example FOO.get('var'), would give a webpack error.

> worker-typescript-template@1.0.0 build
> webpack

asset worker.js 2.33 KiB [emitted] (name: main) 1 related asset
./src/index.ts 219 bytes [built] [code generated]
./src/handler.ts 519 bytes [built] [code generated] [1 error]

ERROR in /Users/akshayrajgollahalli/Documents/GitHub/cloudflare-workers/gollahalli-com-delete-history/src/handler.ts
./src/handler.ts 7:24-34
[tsl] ERROR in /Users/akshayrajgollahalli/Documents/GitHub/cloudflare-workers/gollahalli-com-delete-history/src/handler.ts(7,25)
      TS2304: Cannot find name 'FOO'.
ts-loader-default_e3b0c44298fc1c14
 @ ./src/index.ts 3:18-38

webpack 5.38.1 compiled with 1 error in 1649 ms

Is there a way to get over this?

koeninger commented 3 years ago

declare var FOO: KVNamespace

https://www.typescriptlang.org/docs/handbook/declaration-files/by-example.html#global-variables

https://github.com/cloudflare/workers-types/blob/master/index.d.ts#L582

akshaybabloo commented 3 years ago

Thank you @koeninger

i-mighty commented 3 years ago

Just as a follow up question, Where does the KVNameSpace type live?

koeninger commented 3 years ago

it's in the workers-types project I linked above