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”

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”

Recently my team decided to migrate all views in our Angular 1.x application to React. To me, the value of React is doubled if used together with TypeScript. I enjoy developing views when I have autocompleted and static checks for the view model, used in the view. I also can safely rename elements of the view model, which I prefer doing often and after I have already worked with the model and realized what the best name could be. Moreover, JSX in TypeScript is also…Continue Reading “How TypeScript can teach you web standards”