How to bind to services

Hello,

I am new to workers and trying to understand service binding. In the wrangler init TypeScript project there is an environment interface:
export interface Env {
    // Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
    // MY_KV_NAMESPACE: KVNamespace;
    //
    // Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
    // MY_DURABLE_OBJECT: DurableObjectNamespace;
    //
    // Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
    // MY_BUCKET: R2Bucket;
}


What I am trying to understand is where the values KVNamespace or R2Bucket are coming from. In my wranlger.toml I have a binding = "DB" (in this case D1) but I don't know how to use env.DB in the code since TypeScript says DB does not exist on type Env. I understand it needs to be added into the interface but not sure how to reference it there.
Was this page helpful?