@netlify/edge-handler-types
TypeScript icon, indicating that this package has built-in type declarations

0.34.1 • Public • Published

@netlify/edge-handler-types`

This package contains TypeScript typings for writing Netlify Edge Handlers.

Installation

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

or if you prefer yarn

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:

{
  "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.

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 }),
  );
};

Package Sidebar

Install

npm i @netlify/edge-handler-types

Weekly Downloads

84

Version

0.34.1

License

MIT

Unpacked Size

32 kB

Total Files

25

Last publish

Collaborators

  • seanroberts
  • biilmann
  • eduardoboucas
  • netlify-bot
  • akardet
  • sarahetter
  • mikewen
  • kathmbeck
  • hrishikeshk
  • vitaliyr
  • denar90
  • smnh
  • berdav
  • youvalv
  • serhalp-netlify
  • rmulligan-netlify