Programming

TypeScript Optional Chaining Interim Method

Posted on

ECMAScript has an optional chaining proposal on the way (see TC39 on GitHub). It uses ?. to chain together an expression in a way that forgives a breaking chain. For example, myObj.items[0].data can fail if myObj is null, or undefined, or doesn’t have an items member, or there are no entries in the items collection, […]

Programming

Catching Null and Undefined Without Side Effects

Posted on

This article simply promotes the use of the statement if (x == null) when you want to check if a value is either null or undefined. I keep on having to explain this point, because catching null or undefined without side effects is important. If we break the statement down, there is a very important […]

Programming

Apply TypeScript Types Honestly

Posted on

TypeScript is optionally statically typed, which means you can still write dynamically typed expressions within your TypeScript programs. If you drop into a block of dynamic code, and then want to come back out into statically typed code – you’ll need to introduce the types, and are responsible for the correctness of the type you […]

Programming

Embracing the TypeScript Strict Mode

Posted on

TypeScript has had the strict compiler option for a while now. It enables several more stringent checks, including two of my favourites: noImplicitAny and strictNullChecks. My summary of strict mode would be this… “If using TypeScript is better than using plain JavaScript because of the compiler warnings, why wouldn’t you want to turn the compiler […]

Programming

Deep TypeScript Destructuring

Posted on

When you first encounter TypeScript (or JavaScript) destructuring it looks a little bit magic, especially in object destructuring where it looks like you are doing everything in a mirror (the names go on the right!). If you find destructuring a little confusing – strap yourselves in and we’ll rush our way to an example of […]

Programming

TypeScript Pixel Counter

Posted on

In the process of writing an article on Pie Charts, I was faced with a situation where I needed to programmatically count the pixels on the pie chart in order to reverse-engineer the original values. To do this, I wrote a quick utility in TypeScript to do the following: Load an image Read each pixel […]

Programming

TypeScript Definite Assignment Assertions

Posted on

TypeScript never stops improving, although most changes over the past year have been “non syntactical” – i.e. there have been a huge swathe of improvements to how types are handled, and a large slice of improvements to make the tooling even better. It has a been a while, though, since we got a new character […]

Programming

Code Organisation and Junk

Posted on

Code organisation feels like hard work at times; but there are some mental tricks you can apply to help break the inertia. This article contains a couple of ideas that will help you get moving when you don’t know where to start. I’m not going to go through the steps you need to take to […]

Programming

Stop Writing Web Firmware

Posted on

This has been a problem for a long time. It was a problem with jQuery, it was a problem with AngularJS, it is a problem right now with Angular, Aurelia, Vue, and React. None of these frameworks are at fault, but there is a huge industry-wide issue with people writing all of their code inside […]