2ality – JavaScript and more

フィード

記事のアイキャッチ画像
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>
2日前
記事のアイキャッチ画像
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><ul><li>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).<ul><li>It helps that Node.js now supports <a href="https://nodejs.org/api/modules.html#loading-ecmascript-modules-using-require">“require(esm)”</a> – requiring ESM libraries from CommonJS modules.</li></ul></li><li>I’m only using tsc, but mention how to support other tools via <code>tsconfig.json</code> in section <a href="#compiling-without-tsc">“Compiling TypeScript with tools other than tsc”</a>.</li></ul>
4日前
記事のアイキャッチ画像
Computing with tuples in TypeScript
はてなブックマークアイコン 1
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&lt;string&gt;</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>
10日前
記事のアイキャッチ画像
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>
15日前
記事のアイキャッチ画像
ECMAScript proposal: 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 is currently at stage 3.</p>
18日前
記事のアイキャッチ画像
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>
20日前
記事のアイキャッチ画像
A guide to <code>tsconfig.json</code>
2ality – JavaScript and more
<p>I was never entirely sure which options to put in my <code>tsconfig.json</code> and which ones to omit. To change that, I went through the <a href="https://www.typescriptlang.org/tsconfig/">official documentation</a>, collected the most important options, and documented how to use them in this blog post. The result is a much cleaner <code>tsconfig.json</code> than I had before.</p><ul><li>You can jump directly to the end result, which is shown in <a href="#summary">the summary</a> of this post.</li><li>Or you can let me walk you through the most common options and learn how to best use them yourself.</li><li>As part of my research, I read the <code>tsconfig.json</code> recommendations of several TypeScript programmers. <a href="#tsconfig-recommendations">Links to them</a> are listed at the end.</li></ul><p>I’m curious what your experiences with <code>tsconfig.json</code> are: Do you agree with my choices?</p>
24日前
記事のアイキャッチ画像
ECMAScript 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>Regular expression pattern modifiers attributes reached stage 4 in October 2024 and will probably be part of ECMAScript 2025.</p>
1ヶ月前
記事のアイキャッチ画像
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>
1ヶ月前
記事のアイキャッチ画像
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>
1ヶ月前
記事のアイキャッチ画像
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>
1ヶ月前