# @netlify/edge-handler-types`

This package contains TypeScript typings for writing Netlify Edge Handlers.

## Installation

```sh
npm install --save-dev @netlify/edge-handler-types
```

or if you prefer yarn

```sh
yarn add -D @netlify/edge-handler-types
```

### Configuring tsconfig.json

For the typings to work it is vitally important TypeScript does not try to include its own definitions of global types (e. g. those found normally in a Browser environment).

Thus, it's important you configure the `lib` and `typeRoots` properties in your `tsconfig.json`:

```json
{
  "compilerOptions": {
    "lib": ["ES2020"],
    "typeRoots": [
      "node_modules/@types", // If you use type definitions of other packages
      "node_modules/@netlify" // Include this line for Edge Handler types
    ]
  }
}
```

## Writing Edge Handlers with this package

The types are injected into the global scope. No additional imports are necessary.

```ts
export const onRequest: EdgeHandler = (ev: RequestEvent) => {
  const headers = {
    "content-type": "text/plain",
    "x-cool": "yes",
  };

  ev.replaceResponse(
    new Response("Sent from an Edge Handler written in TypeScript!", { headers }),
  );
};
```
