Skip to content

Instantly share code, notes, and snippets.

@lmammino
Last active October 19, 2022 09:13
Show Gist options
  • Save lmammino/ad16b389742cf78e804ecd988c192e35 to your computer and use it in GitHub Desktop.
Save lmammino/ad16b389742cf78e804ecd988c192e35 to your computer and use it in GitHub Desktop.
Lambda Proxy autocomplete and type checking with JSDoc (and no TypeScript!)

How to get type checking and autocompletion in your IDE without TypeScript for your AWS Lambda code

A quick demo that shows how JSDoc annotations can help you to get autocompletion and type checking without having to write (and transpile!) TypeScript code.

The video version is available here: https://youtube.com/shorts/60zUEc_vs1o

For more AWS tutorials, follow us at @AWSBites

// @ts-check
// Let's add type support to this lambda proxy lambda
// without TypeScript!!!
// let's make it strict!
/**
*
* @param {import('aws-lambda').APIGatewayEvent} event
* @param {import('aws-lambda').Context} context
* @returns {Promise<import('aws-lambda').APIGatewayProxyResult>}
*/
export default async function handler(event, context) {
const username = event?.queryStringParameters?.name || 'world'
const functionName = context.functionName
const bla = event.bla
return {
body: JSON.stringify({ message: `Hello ${username} by ${functionName}!` })
}
}
{
"name": "example",
"version": "1.0.0",
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/aws-lambda": "^8.10.107"
},
"type": "module"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment