Blog
Redux and React: An Introduction
In this post I’m going to briefly explain what redux is, all of the basic elements, and how to set up a React project with redux as your data storage / flow solution using react-redux. You will need some prior knowledge of React; JSX, state, props, context; and ES6 syntax,...
TypeScript Quirks: Arrays vs Tuples
So, in TypeScript we can define an array as being a list of things. This could be a single type of thing, or multiple possible things. Additionally, as briefly covered in a previous post, we can define a tuple… but it’s not necessarily what you’d think.
Writing better code: Finding duplicates in an array
A few days ago at work one of my colleagues posed a question about the most elegant way to find the duplicates in an array (in javascript), and after having seen the variety of solutions that people suggested I thought I’d write a small post about it. Hopefully it’ll help...
Debugging npm dependencies
Earlier today one of our projects randomly started failing tests on our continuous integration platform. This is not the first time something like this has happened. The cause - unpinned dependencies. It wasn’t that we had not pinned our dependencies to a specific version. We always do. It was that...
TypeScript: Extending vs anding vs oring
I felt like this could do with an explanation because for those who are just starting out with typescript, the difference between these three things may not be incredibly obvious. Hopefully I can explain in such a way that it’ll all make sense to you in just a few minutes....
TypeScript: Exact key value pairs
If you create an object like this, although the keys are correctly inferred, all of the values will be of type string.
TypeScript: Get the return type of a function without calling it
Firstly, this might seems like madness… and it kind of is, but there are actually situations where this is a sensible thing to do e.g. when there is a function from another module, that you do not want to call (not yet anyway, you are just typing something else), but...
TypeScript: Strict types in objects, getters, and setters
Out of the box typescript can infer the types of an object… roughly. Unfortunately it cannot infer the types of keys, and only infers basic types, like string and number for values, as opposed to an exact number or string.
If we were to define an object like so:
Find malicious javascript modules in your projects
It came to my attention recently that a bunch of modules with similar names to popular libraries had been published on npm, with the goal of taking people’s environment variables, which may contain important private information. These modules work exactly like the originals, but send your process environment to a...
TypeScript Quirks: Spreading types
The spread operator - amazing. One of my favorite additions to javascript in recent years, and one of the most flexible operators in javascript and typescript alike. Unfortunately though, it does have some limitation currently.