Posts

Typescript - Types vs Interface

Gagandeep Singh
Types A type helps in defining the shape or structure of the javascript value. A type can consist of a single property or method or can have combination of multiple properties and methods. For example, the type of variables below can be inferred by typescript by checking the values assigned to them. let id = 123; //number let name = "Gagandeep Singh"; //string let skills = ["typescript", "react"]; // string[] But in case of an object or complex data structure it’s good to define a type beforehand.

Typescript - Union vs Intersection types

Gagandeep Singh
Union Types Multiple types can be defined on a value by using the | symbol. When a value is expected to have one of many known types, then using union type is the most suitable option (rather than any or unknown). type value = number | boolean; Here value can be either number or boolean. We can also combine custom type using the union operator. interface house { hasDoor: boolean; address: string; } interface building { hasLift: boolean; address: string; } type houseOrBuilding = house | building const hb: houseOrBuilding In above case hb can only access members that are common to all types in the union.

Feature flagging in webpack

Gagandeep Singh
Agile methodologies allows for smaller release to production fairly quickly. This could result in more feature branches/pull requests being created to enable/disable some feature specially when something needs to be tested on production. Other main advantage to use feature flag is that we don’t need to wait for a feature to be completed before it could be deployed to production. The feature flag for that particular feature could be switched off and once the whole feature is completed, tested and deployed to production, the feature flag can again be turned on.

Various loops available in javascript

Gagandeep Singh
This post will focus on the various loops available in the javascript and when to use them. for - Probably the most commonly used loop in any programming language. The for loop runs until a specific condition is true. As seen below, it has 3 parts: i) initialization (i=0) ii) condition (i<5) iii) increment/decrement (i++/i--) for (let i = 0; i < 5; i++) { console.log(i); } for (let i = 5; i >= 0; i--) { console.

useCallback vs useMemo

Gagandeep Singh
useCallback and useMemo are two of the multiple hooks released with React V16. Hooks are javascript functions which help in isolating some functionality from the functional component (hooks cannot be used inside class based components). useCallback - As per the official documents, useCallback “Returns a memoized callback”. Here memoized means maintaining or saving a version of the function in the memory for the given array of one or more dependencies.