2020-06

ES2021: Logical assignment operators

[2020-06-11] dev, javascript, es2021

The ECMAScript proposal “Logical assignment operators” (by Justin Ridgewell and Hemanth HM) introduces the following compound assignment operators:

  • a ||= b
  • a &&= b
  • a ??= b

TypeScript: validating external data

[2020-06-09] dev, javascript, typescript

Data validation means ensuring that data has the desired structure and content.

With TypeScript, validation becomes relevant when we receive external data such as:

  • Data parsed from JSON files
  • Data received from web services

In these cases, we expect the data to fit static types we have, but we can’t be sure. Contrast that with data we create ourselves, where TypeScript continuously checks that everything is correct.

This blog post explains how to validate external data in TypeScript.

TypeScript: narrowing types via type guards and assertion functions

[2020-06-07] dev, javascript, typescript

In TypeScript, a value can have a type that is too general for some operations – for example, a union type. This blog post answers the following questions:

  • What is narrowing of types?
    • (Spoiler: focusing on a subset of an overly general type, in a specific region of a program)
  • What are type guards and assertion functions and how can we use them to narrow types?

Type assertions in TypeScript

[2020-06-06] dev, javascript, typescript

This blog post is about type assertions in TypeScript, which are related to type casts in other languages and performed via the as operator.

The top types any and unknown in TypeScript

[2020-06-03] dev, javascript, typescript

In TypeScript, any and unknown are types that contain all values. In this blog post, we examine how they work.

2020-05

A first look at records and tuples in JavaScript

[2020-05-26] dev, javascript, es proposal

In this blog post, we take a first look at the ECMAScript proposal “Record & Tuple” (by Robin Ricard and Rick Button). This proposal adds two kinds of compound primitive values to JavaScript:

  • Records, immutable compared-by-value versions of plain objects
  • Tuples, immutable compared-by-value versions of Arrays

2020-04

Creating web apps via TypeScript and webpack

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

This blog post describes how to create web apps via TypeScript and webpack. We will only be using the DOM API, not a particular frontend framework. The repository ts-demo-webpack with the files can be downloaded from GitHub.

How does TypeScript work? The bird’s eye view

[2020-04-18] dev, javascript, typescript

This blog post gives the bird’s eye view of how TypeScript works: What is the structure of a typical TypeScript project? What is compiled and how? How can we use IDEs to write TypeScript?

This post is meant to be read before learning how to write TypeScript code (material for doing that is listed at the end).

Strategies for migrating to TypeScript

[2020-04-17] dev, javascript, typescript

This blog post gives an overview of strategies for migrating code bases from JavaScript to TypeScript. It also mentions material for further reading.

Creating CommonJS-based npm packages via TypeScript

[2020-04-16] dev, javascript, typescript

This blog post describes how to use TypeScript to create npm packages with CommonJS modules. All the artifacts that are shown can be downloaded via the GitHub repository ts-demo-npm-cjs (I deliberately have not published it to npm).