TypeScript provides some built-in utility types that help facilitate transformations of types from one form to another.

These utilities are available globally. They can be quite handy in various situations.

TypeScript generics

Before understanding the TypeScript utility types, it is important to understand type aliases and generics. You can create type aliases for any existing type in TypeScript.

type MyString = string;let helloWorldMessage: MyString = 'Hello Wisdom Geek';

Type generics are used to create reusable type aliases. Let us say we had an identity function which returns whatever value is passed back in:

Type generics are used to create reusable type…

Once we start exploring TypeScript, we start using interfaces and types without really understanding the differences between them. I am guilty of doing that as well. It is simple to get started with them and keep using them. But, at some point, it becomes important to know the difference between interface and type.

After all, we can use either of these:

interface Point {
x: number;
y: number;


type Point = {
x: number;
y: number;

The difference between interface and type is more than just the minor syntax declaration. Let us get deeper into it.

Type and type aliases


Writing conditional expressions is pretty easy to do. But there is room for improvement in the way we have been doing it. And with the flexibility that JavaScript provides, we can replace conditionals with clean code by using some good practices. And it can lead to more maintainable code. Let us take a look at writing better conditional expressions in this post.

1. Early returns

When we start learning programming, we are taught that we should only have one return statement. While the advice is not wrong, it becomes challenging to read code if the code base is large. …

As you might know, I recently switched jobs. And in my long journey of finding a new one, there was a moment where I was offered way more money than I had anticipated for a role that I was not as passionate about. And I wish I could say that it was an easy no for me. But it was not. I wanted to say no. But instead, I kept asking myself, “Am I really going to do this?”. And I even talked to quite a few close friends about that decision. And everybody, including my parents, told me that…

Introduction of type hinting opened the gates for a lot of great new features in Python. And data validation and parsing became easier to do with the use of type hints. Pydantic is one such package that enforces type hints at runtime. It throws errors allowing developers to catch invalid data.

Pydantic not only does type checking and validation, it can be used to add constraints to properties and create custom validations for Python variables. It guarantees the types and constraints of the model have been applied and that the data is valid.

This is useful especially when we have…

Every now and then, you come across a JavaScript feature that vastly changes the way you write it. Destructuring, arrow functions, modules have been some of those features for me. Optional chaining is going to be the next one on that list for me.

Optional Chaining is in stage 4 of the ES2020 proposal, therefore should be added to the specification. It changes the way properties inside an object are accessed, especially the deeply nested ones. It is also available as a feature in TypeScript 3.7+.

The challenge

I am pretty sure you have run into null and undefined properties in JavaScript…

With the introduction of type hinting in Python 3.5, static typing and checking Python codes has started to gain popularity. While MyPy was the first tool to do static type checking of Python code, many other frameworks have been built after it. Pyright is one such tool built by Microsoft and is the one that we will be discussing in this post.

Type hints in Python

Python has been a dynamically typed language. While that flexibility has its benefits, it becomes a hassle when working on large scale projects. Inferring the type of an object can be hard at times for the interpreter. …

As we discussed in our post on getting started with Pytest, the framework allows us to re-use tests by making use of test fixtures and parameterized functions. In this post, we will learn how to do so.

We will build on our simple calculator example that we discussed in the previous post and add to it. Without further ado, let us get started.

Adding test fixtures

As we saw in our small example, there is some repetition in the two basic tests that we wrote:

# calculator_test.py
from calculator import add

def test_add():
firstNumber = 2
secondNumber = 1…

Testing our code brings in a variety of benefits, including building confidence in the code’s functioning and having lesser regressions.

Writing and maintaining tests requires some additional work, and that is why we want to leverage tools as much as we can.

Python does provide inbuilt tools such as unittest for supporting testing, but it involves writing a lot of boilerplate code. It also has a limited ability to reuse components (or fixtures in PyTest). Therefore we will be testing Python applications using Pytest instead of other tools. Pytest is the most popular tool among other alternatives as well.


The process to format a number as currency can be a tedious task. It feels like a small task, but the number of lines and the edge cases can keep on increasing when considering factors such as internationalization and different formatting standards. Luckily, ES2015 introduced an internationalization API which can make the process to format a number as currency super easy.

Writing our own formatting function

We can surely put together a hacky function for this, right?

let formatCurrency = (val, currency) => {
let val;
switch (currency) {…

saransh kataria

For over and over, I have failed & in the process of losing it all, I realized that I might actually win.

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