Programming

Visual Studio Code IntelliCode Extension Preview

Posted on

IntelliCode brings AI-assisted power-ups to your auto-completion. It has been in preview within Visual Studio for some time (you can read about Visual Studio IntelliCode here) – but it has now landed in Visual Studio Code, which is exceptionally handy if you’re a TypeScript programmer like me. So what is IntelliCode? It’s a simple VSCode […]

Programming

Create and Hydrate a TypeScript Class from JSON

Posted on

It is pretty common to want to hydrate a class from a JSON value obtained in a service. If you just parse the JSON you get the properties, but not the behaviours that you expect. As this is a reasonably common problem to solve, it is worthing doing it just once. The following function will […]

Programming

TypeScript NotFunction Type

Posted on

I have been working out how to create a TypeScript NotFunction type for a while, in response to a Stack Overflow question. With the arrival of conditional types, I think there may be a way. It’s not perfect – but it does work. The type works by taking all possible types and converting the type […]

Programming

C# Interfaces: Default Implementations

Posted on

The C# 8.0 announcement included a note on default implementations of interface members. If you’ve been programming for long enough, this might make you a little nervous at first thanks to the hangovers of multiple inheritance. Before you chuck out this idea, though, let’s look at it from a different perspective. I’m going to talk […]

Programming

TypeScript Dictarray Options

Posted on

This is one of those cases where a question keeps cropping up, so lots of people are trying to do something that the TypeScript Compiler doesn’t like very much. Yes, it’s time to talk about the TypeScript Dictarray! What’s a Dictarrary? It’s a dictionary that’s also an array. You know… one of these: const dictarray […]

Programming

TypeScript Mixins Part Three

Posted on

Don’t worry, the mechanism for creating TypeScript mixins hasn’t changed, but I just wanted to demonstrate that the technique described in TypeScript Mixins Part Two is valid for use with static properties. Reusing the original example, let’s see what happens if we add static properties to our Flies and Climbs mixins. Not only does this […]

Programming

Getting Started with Cypress and TypeScript

Posted on

Cypress is a front-end testing utility that allows you to write UI tests using Mocha and Chai. It has auto-waits, time-travel (look back at snapshots from within test runs), and automatic discovery of tests. This blog provides a quick start for getting started with Cypress and TypeScript. Cypress NPM Packages Your package.json file will need […]

Programming

Using a Proxy to Intercept Methods

Posted on

This is just a short note on how to use an ECMAScript Proxy to intercept methods. There are plenty of examples that intercept properties, but examples with methods seem absent currently. For demonstration purposes, we’re going to intercept a very famous method. The console log method takes any number of arguments of any type. This […]

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, […]