AWS Lamda Function TypeScript Boilerplate

I have created a boilerplate for TypeScript lambda function. If you are into JavaScript, I have the boilerplate here.

TypeScript is really JavaScript that scales as the official tag line suggests. It is type-safe and the TypeScript specific intellisense provided by Visual Code Studio is amazing. Compared to writing in JavaScript, my code has less errors and clearer intentions. I also find it easier to maintain other people’s TypeScript code than JavaScript code because data model is more precisely expressed.

This is especially true when the lambda function deals with complex data with a bit of transformation logic. What I love most about it is that it makes me a better programmer because I have to be precise about my intention on types of data models or functions or classes.

The boilerplate includes pretty much everything you need. It uses serverless, webpack, serverless-webpack plugin for compilation and deployment. Unit tests and integration tests are configured and examples are included. It should have enough to get you started.

The benefit of TypeScript is huge. The initial learning curve can be steep because it feels like you need to provide types for everything including things you don’t really care. Using JavaScript module without TypeScript supports will frustrate you first time. But, once you get used to it, you will see what I am talking about. My advice is not to worry too much about types first. It is ok to use any to start with if you are not sure. You can always find someone who knows TypeScript very well and seek help from them. That is essentially how I learned TypeScript!

In fact, lambda function is the perfect platform to write you first TypeScript application. Pick something simple and give it a go. If you are going to work on a new lambda function project, it might be a better idea to choose TypeScript. At the end of the day, it is JavaScript. So, if you have lambda running on Node.js already, it shouldn’t be too controversial.

With this boilerplate, the configuration that comes with TypeScript should be minimal. All you need to do is to write you function and deploy. I hope this helps you to get into writing Lambda function in TypeScript.

On the side note, here are some examples of React application written in TypeScript. I am completely converted to TypeScript and use it for any new projects.

Book reading tracker with TypeScript React Redux

LaunchDarkly feature flag dashboard with TypeScript React Redux

Hopefully, these repo helps you to get started with TypeScript!

Front-End
TypeScript: type aliases to check type equality

This post is to analyse how the type equality check by using type aliases proposed by Matt Pocock in his twitter post. These type aliases allow us to elegantly express type equality checks in unit tests. All we need to do is to pass the output and expected types in …

Front-End
Fixing it.only type error in Jest

If you are getting a type error with it.only in Jest, it could be due to incorrect TypeScript typings or incompatible versions of Jest and TypeScript. To resolve this issue, you can try the following steps: Make sure you have the latest versions of Jest and its TypeScript typings installed …

Front-End
yup conditional validation example

Here’s an example of a Yup validation logic where the first input field is optional but, if filled, it must contain only alphabetic characters, and the second input field is required: import * as Yup from “yup”; const validationSchema = Yup.object().shape({ firstField: Yup.string().matches(/^[A-Za-z]*$/, { message: “First field must contain only …