Skip to content

Add missing typeguard exports for event and request type narrowing#304

Draft
Copilot wants to merge 3 commits intofeat/types/support-albfrom
copilot/sub-pr-284
Draft

Add missing typeguard exports for event and request type narrowing#304
Copilot wants to merge 3 commits intofeat/types/support-albfrom
copilot/sub-pr-284

Conversation

Copy link
Contributor

Copilot AI commented Feb 7, 2026

The TypeScript type definitions declared typeguards for events and requests (isApiGatewayEvent, isAlbRequest, etc.) but the JavaScript implementation only exported context typeguards. This caused runtime errors when using these functions.

Changes

  • Added event typeguards (isApiGatewayEvent, isApiGatewayV2Event, isAlbEvent) to lib/typeguards.js
  • Added request typeguards (isApiGatewayRequest, isApiGatewayV2Request, isAlbRequest) to lib/typeguards.js
  • Exported all typeguards from main module in index.js
  • Added null/undefined checks to all typeguard implementations to prevent runtime errors

Usage

import { isApiGatewayEvent, isAlbRequest } from 'lambda-api';

// Event type narrowing
if (isApiGatewayEvent(event)) {
  const sourceIp = event.requestContext.identity.sourceIp;
}

// Request type narrowing in middleware
api.use((req, res, next) => {
  if (isAlbRequest(req)) {
    const targetGroup = req.requestContext.elb.targetGroupArn;
  }
  next();
});

All typeguards now safely handle null/undefined inputs and correctly narrow TypeScript types based on the AWS Lambda event source (API Gateway, API Gateway v2, or ALB).


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 7, 2026 19:38
Co-authored-by: naorpeled <6171622+naorpeled@users.noreply.github.com>
Co-authored-by: naorpeled <6171622+naorpeled@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for generics in type-safe API Add missing typeguard exports for event and request type narrowing Feb 7, 2026
Copilot AI requested a review from naorpeled February 7, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants