#Shorts Type checking and autocompletion in Lambda without TypeScript!
AWS Bites
Did you know that you don't need to use TypeScript to get type checking and autocomplete when writing your Lambdas in Node.js? In this short, we show you how you can simply rely on JSDoc annotations to get in-editor support for type-based auto-completion and type-checking! We will be demonstrating that with a Lambda implementing the API Gateway LambdaProxy integration (the most widely used for APIs). You just need to install the lambda
types with:
npm i --save-dev @types/aws-lambda
Then you can simply import your types using the following JSDoc notation:
@param {import('aws-lambda').APIGatewayEvent} event
@param {import('aws-lambda').Context} context
Full code available here: https://gist.github.com/lmammino/ad16b389742cf78e804ecd988c192e35
TypeScript is great, but JSDoc can give you most of the same advantages without having to rely on transpilation.
Did you enjoy this short? Did you know about this trick? Let us know in the comments!
Credits:
Music by prazkhanal from Pixabay ... https://www.youtube.com/watch?v=60zUEc_vs1o
1965139 Bytes