In the previous article, we declare types and create a function to make and validate the type.

But it will take too much time if we want to create these functions and validators for each model we want to use.

In this article, we are going to use io-ts library to automate these boring tasks.

The final project is available here:

mohsensaremi/reflecting-business-logic-rules-into-the-domain-models

Contribute to mohsensaremi/reflecting-business-logic-rules-into-the-domain-models development by creating an account on…

github.com

Installation

yarn add io-ts fp-ts

So what is fp-ts ?

fp-ts is a functional programming utility for typescript and is a peer dependency for io-ts .

We are not going to talk about functional programming in this article.

We only discuss a little about Either monad.

Codec

io-ts represent our type with something called Codec.

A codec has decode and encode functions.

We create and validate our input data with decode function and put back the data in normal shape using encode function.

#domain-modeling #typescript #business-logic #domain-driven-design #domain-model

Reflecting business logic rules into the domain models using typescript — Part 3
8.20 GEEK