DEV Community

Alex Chiu
Alex Chiu

Posted on • Edited on • Originally published at chiubaca.com

2 1

TypeScript and Netlify Functions

Did you know that Netlify Functions are just using AWS Lambdas behind the scenes?

This means you can use the same type definitions available for aws-lambda for your Netlify functions too. Install the aws-lamda types by running the following.

npm install @types/aws-lambda --save-dev
Enter fullscreen mode Exit fullscreen mode

You only need to import the APIGatewayProxyEvent, APIGatewayProxyCallback types like so.

import { APIGatewayProxyEvent, APIGatewayProxyCallback } from "aws-lambda";

export const handler = async function (
  event: APIGatewayProxyEvent,
  context: any,
  callback: APIGatewayProxyCallback
) {
  // Do some stuff here 
};
Enter fullscreen mode Exit fullscreen mode

Note, there are no type declarations available for context as this includes properties and methods specific to Netlify such as Netlify Identity .

However, having auto completion for event alone makes this hugely useful!

I'm putting together some TypeScript Netlify Functions examples over at this repo. Feel free to give it a star if you find it helpful.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay