CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-edge-runtime--types

TypeScript global types for using Edge Runtime.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

Edge Runtime Types

Edge Runtime Types provides TypeScript global type definitions for the Edge Runtime environment. This package makes Edge Runtime-specific APIs available globally in TypeScript projects without explicit imports, enabling type-safe development of serverless functions and edge applications.

Package Information

  • Package Name: @edge-runtime/types
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @edge-runtime/types --save-dev

Core Imports

This package provides global type definitions that extend the TypeScript global scope. No explicit imports are required - simply install the package and the global types become available:

/// <reference types="@edge-runtime/types" />

// Global addEventListener is now typed for Edge Runtime
addEventListener('fetch', (event) => {
  // event is automatically typed as Edge.FetchEvent
  const { request } = event;
  event.respondWith(new Response('Hello'));
});

// Global constructors are available with proper typing
const pattern = new URLPattern('/api/*');
const fetchEvent = new FetchEvent(request);

To access Edge Runtime primitives directly in your code:

import * as Edge from '@edge-runtime/primitives';

Basic Usage

// TypeScript configuration (tsconfig.json)
{
  "compilerOptions": {
    "types": ["@edge-runtime/types"]
  }
}

// In your Edge Runtime function
addEventListener('fetch', (event: FetchEvent) => {
  const { request } = event;
  
  // event and request are fully typed
  event.respondWith(
    new Response('Hello from Edge Runtime', {
      status: 200,
      headers: { 'Content-Type': 'text/plain' }
    })
  );
});

// Global EdgeRuntime identifier is available
console.log(typeof EdgeRuntime); // "object"

Capabilities

Global Event Listener Registration

Provides type-safe addEventListener function specifically for Edge Runtime's 'fetch' events.

/**
 * Adds an event listener for 'fetch' events in Edge Runtime
 * @param type - Event type, must be 'fetch'
 * @param listener - Event handler receiving Edge.FetchEvent
 */
function addEventListener(
  type: 'fetch',
  listener: (event: Edge.FetchEvent) => void,
): void;

Global Runtime Constants

Edge Runtime identifier and global scope typing.

/**
 * Edge Runtime identifier constant (empty object)
 */
const EdgeRuntime: Record<never, never>;

/**
 * Global object typed as Edge Runtime primitives namespace
 * Makes all Edge Runtime primitives available globally
 */
const globalThis: typeof Edge;

Global Constructor References

Direct access to Edge Runtime constructors in the global scope.

/**
 * FetchEvent constructor reference from Edge Runtime primitives
 */
const FetchEvent: typeof Edge.FetchEvent;

/**
 * URLPattern constructor reference from Edge Runtime primitives
 */
const URLPattern: typeof Edge.URLPattern;

Dependency Relationship

This package depends on @edge-runtime/primitives and makes its types available globally. The actual API implementations (FetchEvent, URLPattern, etc.) are provided by the primitives package, while this package handles the global type declarations.

/**
 * This package imports from @edge-runtime/primitives and declares global types
 */
import * as Edge from '@edge-runtime/primitives';

// Global declarations make Edge primitives available without imports
declare global {
  function addEventListener(
    type: 'fetch',
    listener: (event: Edge.FetchEvent) => void,
  ): void;
  const EdgeRuntime: Record<never, never>;
  const globalThis: typeof Edge;
  const FetchEvent: typeof Edge.FetchEvent;
  const URLPattern: typeof Edge.URLPattern;
}

Types

This package provides global TypeScript type definitions by extending the global scope. When installed, the following types become available:

  • addEventListener: Type-safe event listener registration for 'fetch' events
  • EdgeRuntime: Constant identifier for the runtime environment
  • globalThis: Typed as Edge Runtime primitives namespace
  • FetchEvent: Global constructor reference for fetch events
  • URLPattern: Global constructor reference for URL pattern matching

All other Edge Runtime APIs (Request, Response, crypto, streams, etc.) are available through the @edge-runtime/primitives dependency and are accessible globally when using this types package.

TypeScript Configuration

To use this package, add it to your TypeScript configuration:

{
  "compilerOptions": {
    "types": ["@edge-runtime/types"],
    "lib": ["ES2019"]
  }
}

Or reference it directly in your TypeScript files:

/// <reference types="@edge-runtime/types" />

Environment Requirements

  • Node.js: >=18
  • TypeScript: Any version supporting ES2019
  • Dependencies: @edge-runtime/primitives (automatically installed)
  • Runtime: Edge Runtime environment (Vercel Edge Functions, Cloudflare Workers, etc.)

Install with Tessl CLI

npx tessl i tessl/npm-edge-runtime--types
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@edge-runtime/types@4.0.x
Publish Source
CLI
Badge
tessl/npm-edge-runtime--types badge