Photo by Adeolu Eletu on Unsplash

My Aim

I want to specify validation rules for the objects I am using in my typescript apps in the most ergonomic, hence elegant, manner possible.


I will use Joi and JavaScript decorators. Here’s a small UML diagram to summarize the approach:

Photo by Nicholas Barbaros on Unsplash

When we need a single instance of an object, of a specific class, to exist in our application, we use the Singleton pattern. Now, the pattern itself is frowned upon in some circles and is seen as an anti-pattern.

Some of the reasons the Singleton is seen as an anti-pattern are:

  • It can be technical debt in disguise. The assumption that there will only be a need for one instance of the class during the lifetime of the application can be falsified in the future. This can lead to tedious refactoring.
  • The introduction of global state into the application.
  • The…

Photo by Matt Schwartz on Unsplash

The Aim

I want the objects I use in my TypeScript code to let me set multiple properties on them in one go. My objects must have a method setProps such that when given a properly typed map of properties, the method sets the corresponding properties on the objects.

The Approach

I have a base class, say BaseObject, that has the publicsetProps method. setProps must take parameters that are compatible with the instance of a class derived from BaseClass. This is achieved with generics. The method will look like the following piece of code:

I constrain the type parameter T to represent a…

Photo by John Doyle on Unsplash

My Aim

When writing back-end NodeJS APIs in Typescript, I don’t want to worry about the validity of the data my services are consuming or producing. Given I have correctly captured the business rules and the data validity criteria, I want to be able to trust that the data I am working with is always valid.


The basic tool I will use here are Joi and a set of abstractions I will present in coming paragraphs :

Photo by Thomas Kelley on Unsplash


Essentially, initializing arrays in javascript can happen in one of four ways:

  • With Array literal initialization, such as in let myArray = [1,2]
  • With Array initialization with undefined, as in new Array(arrayLength)
  • With Array initialization with given elements, as in new Array(el1,el2)
  • With the Array.prototype.of method, as in // -> [7]

This being known, there eventually comes a time when a learning javascript developer will need to have more control over the initialization of arrays. In the coming sections we will explore common array initialization questions, as well as some solutions for the power javascript developer to-be.

Question: How to initialize an array with the same value?

It’s a recurring…

Photo by Ricky Kharawala on Unsplash


A few weeks ago, I decided to revisit Dependency Injection (DI) in the PHP world and quickly build a simple one. I looked at various article including the one by Mustafa Magdi and that by Andrew Carter, among others. With all the powerful and well know PHP DI containers out there, why go through the trouble? I figured that there must be some lessons to learn.

Before going any further, DI can be defined as:

Photo by Gilly Stewart on Unsplash

In a previous article, I describe an approach to a generic PHP Singleton pattern that can be summarized by the following diagram:

Patrick Assoa Adou

Solutions Architect and Coder

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store