2ality – JavaScript and more
フィード

Learning web development: JSON and processing files in Node.js
2ality – JavaScript and more
<p>In this chapter, we explore the popular data format <em>JSON</em>. And we implement shell commands via Node.js that read and write files.</p>
15時間前

Learning web development: JavaScript Maps
2ality – JavaScript and more
<p>In this chapter, we’ll explore the data structure <code>Map</code> (a class) which lets us translate (“map”) from an input value to an output value. We’ll use a Map to display text upside-down in a terminal!</p>
2日前

Learning web development: JavaScript exceptions
2ality – JavaScript and more
<p>In this chapter, we look at <em>exceptions</em> in JavaScript. They are a way of handling errors. We’ll need them for the next chapter.</p>
3日前

JavaScript’s trademark problem
1

2ality – JavaScript and more
<p>In this blog post, we discuss Oracle’s trademark of the word “JavaScript”:</p><ul><li>What are the problems caused by that trademark?</li><li>How can we fix those problems?</li></ul>
3日前

Learning web development: Plain objects in JavaScript
2ality – JavaScript and more
<p>In this chapter, we learn how to create <em>plain objects</em> with properties. We use them to create a simple flash card app.</p>
4日前

Learning web development: Modules and testing in JavaScript
2ality – JavaScript and more
<p>So far, all of our JavaScript code resided in a single file – be it an <code>.html</code> file or a <code>.js</code> file. In this chapter, we learn how to split it up into multiple files. And how to automatically test if the code we write is correct.</p>
5日前

Learning web development: Web servers
2ality – JavaScript and more
<p>In this chapter, we run a web server on our own computer and use it to serve a web app.</p>
6日前

Learning web development: Shells and Node.js
2ality – JavaScript and more
<p>In this chapter we explore two topics:</p><ul><li>A <em>shell</em> is like browser console, but for the operating system instead of for JavaScript. It helps us with programming by running the tools (programs) we need to get things done.</li><li><em>Node.js</em> is a program that lets us run JavaScript code outside browsers – which we can use for a variety of things.</li></ul>
7日前

Learning web development: Loops in JavaScript
2ality – JavaScript and more
<p>In this chapter, we learn how to do things repeatedly in JavaScript.</p>
9日前

Learning web development: Booleans, comparisons and <code>if</code> statements in JavaScript
2ality – JavaScript and more
<p>In this chapter, we learn about tools for only running a piece of code if a condition is met: truth values (booleans), comparisons and <code>if</code> statements.</p>
12日前

Learning web development: Arrays in JavaScript
2ality – JavaScript and more
<p>In this chapter we look at one way of storing more than one value in a variable: <em>arrays</em>.</p>
14日前

Learning web development: Strings and methods in JavaScript
2ality – JavaScript and more
<p>In the last chapter, we worked with numbers. In this chapter, we’ll work with text and write our first applications.</p>
15日前

Learning web development: Numbers, variables, functions in JavaScript
2ality – JavaScript and more
<p>In this chapter, we take the very first steps with JavaScript and learn about numbers, variables and functions.</p>
17日前

New series of blog posts: learning web development
2ality – JavaScript and more
<p>This blog post provides an overview of my new series of blog posts called “Learning web development”.</p>
18日前

Ecma International approves ECMAScript 2025: What’s new?
2ality – JavaScript and more
<p>On 25 June 2025, the 129th Ecma General Assembly approved the ECMAScript 2025 language specification (<a href="https://ecma-international.org/news/ecma-international-approves-new-standards-11/">press release</a>, <a href="https://github.com/tc39/ecma262/releases/tag/es2025">GitHub release</a>), which means that it’s officially a standard now.</p><p>This blog post explains what’s new.</p>
2ヶ月前

Tips for making regular expressions easier to use in JavaScript
2ality – JavaScript and more
<p>In this blog post, we explore ways in which we can make regular expressions easier to use.</p>
2ヶ月前

TypeScript: checking Map keys and Array indices
2ality – JavaScript and more
<p>JavaScript has two common patterns:</p><ul><li>Maps: We check the existence of a key via <code>.has()</code> before retrieving the associated value via <code>.get()</code>.</li><li>Arrays: We check the length of an Array before performing an indexed access.</li></ul><p>These patterns don’t work as well in TypeScript. This blog post explains why and presents alternatives.</p>
2ヶ月前

How TypeScript solved its global <code>Iterator</code> name clash
2ality – JavaScript and more
<p>In ECMAScript 2025, JavaScript gets a class <code>Iterator</code> with iterator helper methods. This class conflicts with TypeScript’s existing types for iterators. In this blog post, we explore why that is and how TypeScript solves that conflict.</p>
2ヶ月前

Styling console text in Node.js
2ality – JavaScript and more
<p>In this blog post, we explore how we can style text that we log to the console in Node.js.</p><p>Some of the examples use a Unix shell but most of the code should also work on Windows.</p>
4ヶ月前

Converting values to strings in JavaScript has pitfalls
2ality – JavaScript and more
<p>Converting values to strings in JavaScript is more complicated than it might seem:</p><ul><li>Most approaches have values they can’t handle.</li><li>We don’t always see all of the data.</li></ul>
4ヶ月前

Deploying TypeScript: recent advances and possible future directions
2ality – JavaScript and more
<p>In this blog post we look at:</p><ul><li>The current best practice for deploying library packages: <code>.js</code>, <code>.js.map</code>, <code>.d.ts</code>, <code>.d.ts.map</code>, <code>.ts</code></li><li>Recent new developments in compiling and deploying TypeScript: type stripping, isolated declarations, JSR, etc.</li><li>What the future of deploying TypeScript might look like: type stripping in browsers, etc.</li></ul>
5ヶ月前

Ideas for making TypeScript better at testing types
2ality – JavaScript and more
<p>In this blog post, we examine how we can test types in TypeScript:</p><ul><li>First, we look at the library <code>asserttt</code> and the CLI tool <code>ts-expect-error</code>.</li><li>Then, we consider which functionality could be built into TypeScript.</li></ul>
5ヶ月前

Could JavaScript have synchronous <code>await</code>?
2ality – JavaScript and more
<p>In JavaScript, code has <em>color</em>: It is either synchronous or asynchronous. In this blog post, we explore:</p><ul><li>The problems caused by that</li><li>How to fix them via synchronous <code>await</code></li><li>The two downsides that prevent synchronous <code>await</code> from being practical</li></ul>
5ヶ月前

A closer look at the details behind the Go port of the TypeScript compiler
2ality – JavaScript and more
<p>Today’s <a href="https://devblogs.microsoft.com/typescript/typescript-native-port/">announcement</a> by Microsoft:</p><blockquote><p>[...] we’ve begun work on a native port of the TypeScript compiler and tools. The native implementation will drastically improve editor startup, reduce most build times by 10×, and substantially reduce memory usage.</p></blockquote><p>This blog post looks at some of the details behind the news.</p>
6ヶ月前

Unions and intersections of object types in TypeScript
2ality – JavaScript and more
<p>In this blog post, we explore what unions and intersections of object types can be used for in TypeScript.</p>
6ヶ月前

My sales pitch for TypeScript
2ality – JavaScript and more
<p>Roughly, TypeScript is JavaScript plus type information. The latter is removed before TypeScript code is executed by JavaScript engines. Therefore, writing and deploying TypeScript is more work. Is that added work worth it? In this blog post, I’m going to argue that yes, it is. Read it if you are skeptical about TypeScript but interested in giving it a chance.</p>
6ヶ月前

What is TypeScript? An overview for JavaScript programmers
2ality – JavaScript and more
<p>Read this blog post if you are a JavaScript programmer and want to get a rough idea of what using TypeScript is like (think first step before learning more details). You’ll get answers to the following questions:</p><ul><li>How is TypeScript code different from JavaScript code?</li><li>How is TypeScript code run?</li><li>How does TypeScript help during editing in an IDE?</li><li>Etc.</li></ul><p>Note: <strong>This blog post does not explain why TypeScript is useful.</strong> If you want to know more about that, you can read <a href="https://exploringjs.com/ts/book/ch_why-typescript.html">my TypeScript sales pitch</a>.</p>
6ヶ月前

Simple TypeScript playgrounds via <code>node --watch</code>
2ality – JavaScript and more
<p>Now that Node.js has <a href="https://2ality.com/2025/01/nodejs-strip-type.html">built-in support for TypeScript</a>, we can use it as the foundation of simple playgrounds that let us interactively explore TypeScript code.</p>
6ヶ月前

Testing types in TypeScript
2ality – JavaScript and more
<p>In this blog post, we explore how we can test that complicated TypeScript types work as expected. To do that, we need assertions at the type level and other tools.</p>
6ヶ月前

The unexpected way in which conditional types constrain type variables in TypeScript
2ality – JavaScript and more
<p>The TypeScript handbook makes an interesting <a href="https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#conditional-type-constraints">statement</a>: “Often, the checks in a conditional type will provide us with some new information. Just like narrowing with type guards can give us a more specific type, the true branch of a conditional type will further constrain generics by the type we check against.”</p><p>In this blog post, we’ll see that this goes further than you may think.</p>
6ヶ月前

The bottom type <code>never</code> in TypeScript
2ality – JavaScript and more
<p>In this blog post, we look at the special TypeScript type <code>never</code> which, roughly, is the type of things that never happen. As we’ll see, it has a surprising number of applications.</p>
6ヶ月前

Array type notations: <code>T[]</code> vs. <code>Array<T></code> in TypeScript
2ality – JavaScript and more
<p>In this blog post, we explore two equivalent notations for Arrays in TypeScript: <code>T[]</code> and <code>Array<T></code>. I prefer the latter and will explain why.</p>
6ヶ月前

Symbols in TypeScript
2ality – JavaScript and more
<p>In this blog post, we examine how TypeScript handles JavaScript symbols at the type level.</p><p>If you want to refresh your knowledge of JavaScript symbols, you can check out chapter <a href="https://exploringjs.com/js/book/ch_symbols.html">“Symbols”</a> of “Exploring JavaScript”.</p>
6ヶ月前

Conditional types in TypeScript
2ality – JavaScript and more
<p>A conditional type in TypeScript is an if-then-else expression: Its result is either one of two branches – which one depends on a condition. That is especially useful in generic types. Conditional types are also an essential tool for working with union types because they let us “loop” over them. Read on if you want to know how all of that works.</p>
6ヶ月前

Mapped types in TypeScript
2ality – JavaScript and more
<p>A mapped type is a loop over keys that produces an object or tuple type and looks as follows:</p><pre><code class="language-ts">{[<span class="hljs-title class_">PropKey</span> <span class="hljs-keyword">in</span> <span class="hljs-title class_">PropKeyUnion</span>]: <span class="hljs-title class_">PropValue</span>}</code></pre><p>In this blog post, we examine how mapped types work and see examples of using them. Their most importing use cases are transforming objects and mapping tuples.</p>
7ヶ月前

TypeScript: extracting parts of compound types via <code>infer</code>
2ality – JavaScript and more
<p>In this blog post, we explore how we can extract parts of compound types via the <code>infer</code> keyword.</p><p>It helps if you are loosely familiar with conditional types. You can check out chapter <a href="https://exploringjs.com/ts/book/ch_conditional-types.html#ch_conditional-types">“Conditional types”</a> in “Exploring TypeScript” to read up on them.</p>
7ヶ月前

TypeDoc: testing code examples in doc comments
2ality – JavaScript and more
<p>TypeDoc now lets us refer to parts of other files via <code>{@includeCode}</code>. In this blog post, I explain how that works and why it’s useful.</p>
7ヶ月前

TypeScript: the <code>satisfies</code> operator
2ality – JavaScript and more
<p>TypeScript’s <code>satisfies</code> operator lets us check the type of a value (mostly) without influencing it. In this blog post, we examine how exactly it works and where it’s useful.</p>
7ヶ月前

Read-only accessibility in TypeScript
2ality – JavaScript and more
<p>In this blog post, we look at how can make things “read-only” in TypeScript – mainly via the keyword <code>readonly</code>.</p>
7ヶ月前

Tutorial: publishing ESM-based npm packages with TypeScript
2ality – JavaScript and more
<p>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:</p>
7ヶ月前

Computing with tuple types in TypeScript
2ality – JavaScript and more
<p>JavaScript’s Arrays are so flexible that TypeScript provides two different kinds of types for handling them:</p><ul><li>Array types for arbitrary-length sequences of values that all have the same type – e.g.: <code>Array<string></code></li><li>Tuple types for fixed-length sequences of values where each one may have a different type – e.g.: <code>[number, string, boolean]</code></li></ul><p>In this blog post, we look at the latter – especially how to compute with tuples at the type level.</p>
7ヶ月前

Template literal types in TypeScript: parsing during type checking and more
2ality – JavaScript and more
<p>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:</p><ul><li>Static syntax checking for string literals</li><li>Transforming the casing of property names (e.g. from hyphen case to camel case)</li><li>Concisely specifying large string literal union types</li></ul>
7ヶ月前

ECMAScript 2025 feature: RegExp escaping
2ality – JavaScript and more
<p>The ECMAScript proposal <a href="https://github.com/tc39/proposal-regex-escaping">“RegExp escaping”</a> (by Jordan Harband and Kevin Gibbons) specifies a function <code>RegExp.escape()</code> that, given a string <code>text</code>, creates an escaped version that matches <code>text</code> – if interpreted as a regular expression.</p><p>This proposal reached stage 4 on 2025-02-18.</p>
7ヶ月前

TypeScript enums: use cases and alternatives
2ality – JavaScript and more
<p>In this blog post, we take a closer look at TypeScript enums:</p><ul><li>How do they work?</li><li>What are their use cases?</li><li>What are the alternatives if we don’t want to use them?</li></ul><p>The blog post concludes with recommendations for what to use when.</p>
7ヶ月前

A guide to <code>tsconfig.json</code>
2ality – JavaScript and more
<p>I never felt confident about my <code>tsconfig.json</code>. To change that, I went through the <a href="https://www.typescriptlang.org/tsconfig/">official documentation</a>, collected all common options, and documented them in this blog post:</p><ul><li><p>This knowledge will enable you to write a <code>tsconfig.json</code> that is cleaner and that you’ll fully understand.</p></li><li><p>If you don’t have the time to read the post, you can jump to the summary at the end where I show the <code>tsconfig.json</code> that I use now – along with recommendations for adapting it to different use cases (npm package, app, etc.).</p></li><li><p>I also link to <a href="#tsconfig-recommendations">the <code>tsconfig.json</code> recommendations</a> by several well-known TypeScript programmers. (I went through them when I researched this post.)</p></li></ul><p>I’m curious what your experiences with <code>tsconfig.json</code> are: Do you agree with my choices?</p>
8ヶ月前

ECMAScript 2025 feature: regular expression pattern modifiers
2ality – JavaScript and more
<p>Traditionally, we could only apply regular expression flags such as <code>i</code> (for ignoring case) to all of a regular expression. The ECMAScript feature <a href="https://github.com/tc39/proposal-regexp-modifiers">“Regular Expression Pattern Modifiers”</a> (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.</p><p>This proposal reached stage 4 on 2024-10-08.</p>
8ヶ月前

ECMAScript feature: import attributes
2ality – JavaScript and more
<p>The ECMAScript feature <a href="https://github.com/tc39/proposal-import-attributes">“Import Attributes”</a> (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.</p><p>Import attributes reached stage 4 in October 2024 and will probably be part of ECMAScript 2025.</p>
8ヶ月前

Node’s new built-in support for TypeScript
2ality – JavaScript and more
<p>Starting with <a href="https://nodejs.org/en/blog/release/v23.6.0">v23.6.0</a>, Node.js supports TypeScript without any flags. This blog post explains how it works and what to look out for.</p>
8ヶ月前

WebAssembly as an ecosystem for programming languages
2ality – JavaScript and more
<p>In this blog post, we look at how WebAssembly has become an ecosystem for many programming languages and what technologies enable that.</p>
8ヶ月前