Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dario-piotrowicz/nitro-generic-wrangler-env-type-example
https://github.com/dario-piotrowicz/nitro-generic-wrangler-env-type-example
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/dario-piotrowicz/nitro-generic-wrangler-env-type-example
- Owner: dario-piotrowicz
- Created: 2024-03-24T22:20:58.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-03-24T22:21:11.000Z (8 months ago)
- Last Synced: 2024-04-18T06:19:59.889Z (7 months ago)
- Language: TypeScript
- Size: 191 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Nitro generic `wrangler` `Env` type example
This is a minimal example showing how the `Env` type introduced in `wrangler` in [`workers-sdk/#5363`](https://github.com/cloudflare/workers-sdk/pull/5363) can be used to easily customize the type of the `env` object that [`nitro-cloudflare-dev`](https://github.com/pi0/nitro-cloudflare-dev) exposes.
All that is needed to customize the type of the `env` object is by adding to the `wrangler` `env` interface declaration the desired types, like so for example:
![content of types.d.ts](./types.d.ts.png)Afterwards the `env` object present on the h3 event object should include the correct types:
![the types correctly inferred in a nitro route](./types-in-route.png)## Instructions
- Install the dependencies (using `pnpm`)
```
$ pnpm i
```- Tweak the type `Env` interface in `types.d.ts`
- See how such types get correctly inferred in `server/routes/index.ts`