2020-02

Alternatives to enums in TypeScript

[2020-02-22] dev, javascript, typescript

A recent blog post explored how TypeScript enums work. In this blog post, we take a look at alternatives to enums.

Class-related types in TypeScript

[2020-02-19] dev, javascript, typescript

In this blog post about TypeScript, we examine types related to classes and their instances.

Sections in source code

[2020-02-14] dev, javascript, ide

In this blog post, I’ll briefly explain the idea of having sections in source code. The IDE Visual Studio Code has a related concept: folding regions.

TypeScript: exhaustiveness checks via exceptions

[2020-02-14] dev, javascript, typescript

TypeScript supports exhaustiveness checking for enums and similar types. This blog post shows how to use idiomatic JavaScript for this kind of check.

2020-01

Typing objects in TypeScript

[2020-01-30] dev, javascript, typescript

In this blog post, we will explore how objects and properties are typed statically in TypeScript.

Adding special values to types in TypeScript

[2020-01-26] dev, javascript, typescript

One way of understanding types is as sets of values. Sometimes there are two levels of values:

  • Base level: normal values
  • Meta level: special values

In this blog post, we examine how we can add special values to base-level types.

TypeScript enums: How do they work? What can they be used for?

[2020-01-24] dev, javascript, typescript

This blog post answers the following two questions:

  • How do TypeScript’s enums work?
  • What can they be used for?

A class-based enum pattern for JavaScript

[2020-01-13] dev, javascript, pattern

In this blog post, we examine a pattern for implementing enums in JavaScript that is based on classes. We’ll also take a look at Enumify, a library that helps with the enum pattern.

JavaScript regular expressions: /g, /y, and .lastIndex

[2020-01-01] dev, javascript, regexp

In this blog post, we examine how the RegExp flags /g and /y work and how they depend on the RegExp property .lastIndex. We’ll also discover an interesting use case for .lastIndex that you may not have considered yet.

2019-12

Simple pluralization via Intl.PluralRules

[2019-12-29] dev, javascript, intl

In this blog post, we’ll explore a very simple way to handle reporting of numbers of items that respects grammatical number (in English: singular and plural).