2025-02

Read-only accessibility in TypeScript

[2025-02-06] dev, typescript

In this blog post, we look at how can make things “read-only” in TypeScript – mainly via the keyword readonly.

Tutorial: publishing ESM-based npm packages with TypeScript

[2025-02-04] dev, typescript

During the last two years, ESM support in TypeScript, Node.js and browsers has made a lot of progress. In this blog post, I explain my modern setup that is relatively simple – compared to what we had to do in the past:

  • It is intended for packages that can afford to ignore backward compatibility. The setup has worked well for me for a while – since TypeScript 4.7 (2022-05-24).
    • It helps that Node.js now supports “require(esm)” – requiring ESM libraries from CommonJS modules.
  • I’m only using tsc, but mention how to support other tools via tsconfig.json in section “Compiling TypeScript with tools other than tsc”.

2025-01

Computing with tuples in TypeScript

[2025-01-29] dev, typescript

JavaScript’s Arrays are so flexible that TypeScript provides two different kinds of types for handling them:

  • Array types for arbitrary-length sequences of values that all have the same type – e.g.: Array<string>
  • Tuple types for fixed-length sequences of values where each one may have a different type – e.g.: [number, string, boolean]

In this blog post, we look at the latter – especially how to compute with tuples at the type level.

Template literal types in TypeScript: parsing during type checking and more

[2025-01-24] dev, typescript

In this blog post, we take a closer look at template literal types in TypeScript: While their syntax is similar to JavaScript’s template literals, they operate at the type level. Their use cases include:

  • Static syntax checking for string literals
  • Transforming the casing of property names (e.g. from hyphen case to camel case)
  • Concisely specifying large string literal union types

ECMAScript proposal: RegExp escaping

[2025-01-21] dev, javascript, es proposal

The ECMAScript proposal “RegExp escaping” (by Jordan Harband and Kevin Gibbons) specifies a function RegExp.escape() that, given a string text, creates an escaped version that matches text – if interpreted as a regular expression.

This proposal is currently at stage 3.

TypeScript enums: use cases and alternatives

[2025-01-19] dev, typescript

In this blog post, we take a closer look at TypeScript enums:

  • How do they work?
  • What are their use cases?
  • What are the alternatives if we don’t want to use them?

The blog post concludes with recommendations for what to use when.

A guide to tsconfig.json

[2025-01-15] dev, typescript

I was never entirely sure which options to put in my tsconfig.json and which ones to omit. To change that, I went through the official documentation, collected the most important options, and documented how to use them in this blog post. The result is a much cleaner tsconfig.json than I had before.

  • You can jump directly to the end result, which is shown in the summary of this post.
  • Or you can let me walk you through the most common options and learn how to best use them yourself.
  • As part of my research, I read the tsconfig.json recommendations of several TypeScript programmers. Links to them are listed at the end.

I’m curious what your experiences with tsconfig.json are: Do you agree with my choices?

ECMAScript feature: regular expression pattern modifiers

[2025-01-10] dev, javascript, es proposal

Traditionally, we could only apply regular expression flags such as i (for ignoring case) to all of a regular expression. The ECMAScript feature “Regular Expression Pattern Modifiers” (by Ron Buckton) enables us to apply them to only part of a regular expression. In this blog post we examine how they work and what their use cases are.

Regular expression pattern modifiers attributes reached stage 4 in October 2024 and will probably be part of ECMAScript 2025.

ECMAScript feature: import attributes

[2025-01-09] dev, javascript, es proposal

The ECMAScript feature “Import Attributes” (by Sven Sauleau, Daniel Ehrenberg, Myles Borins, Dan Clark and Nicolò Ribaudo) helps with importing artifacts other than JavaScript modules. In this blog post, we examine what that looks like and why it’s useful.

Import attributes reached stage 4 in October 2024 and will probably be part of ECMAScript 2025.

Node’s new built-in support for TypeScript

[2025-01-08] dev, javascript, typescript

Starting with v23.6.0, Node.js supports TypeScript without any flags. This blog post explains how it works and what to look out for.