Unlike intuitive types such as string or number, the types any, void, never, undefined and null might cause a confusion for a newbie TypeScript developer. In this post, I will share what I have learned about these types. Any The simplest one is any. From the spec: The Any type is used to represent any JavaScript value. The Any type is a supertype of all types and is assignable to and from all types. In general, in places where a type is not explicitly provided…Continue Reading “What are TypeScript’s any, void, never, undefined and null types”

JavaScript if far from being the best-designed language in the world. I personally often feel myself like in the mine field when coding in it. But it evolves and gets better and better. I can increasingly better express the ideas in JavaScript and I feel it becomes truly powerful and pretty pleasant language to use. Here, I want to share how today one can calculate the sum of the array of numbers. The example is contrived but this example is always used in the schools…Continue Reading “Using array destructuring and recursion to make your JavaScript algorithms shine”

Recently I could not figure out how to types-safely update immutable object in TypeScript. The problem is that in JavaScript the object spread feature is used for this task, like so: let o1 = { x: 5, y: 6 }; o1 = { …o1, y: 10 }; console.log(JSON.stringify(o1)); // “{‘x’:5,’y’:10}” But if you have accidentally missspelled the property you want to update, object spread will add a new propery instead of updating old one: interface Point { x: number, y: number } let o1: Point…Continue Reading “Updating an immutable object in TypeScript”