2ality – JavaScript and more
フィード
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>
1日前
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<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
1
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>
12日前
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>
15日前
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>
17日前
A checklist for your <code>tsconfig.json</code>
2ality – JavaScript and more
<p>In order to feel more confident about my <code>tsconfig.json</code>, I decided to go through the <a href="https://www.typescriptlang.org/tsconfig/"><code>tsconfig.json</code> documentation</a>, collect all commonly used options and describe them below:</p><ul><li>You can come along for the whole ride and go through the options with me. Afterward, you should be able to understand all of your tsconfig.</li><li>Or you can skip ahead to <a href="#summary">the summary</a> at the end.</li><li>I also list <a href="#tsconfig-recommendations">recommendations for <code>tsconfig.json</code></a> by several other people.</li></ul><p>I’m curious what your experiences with <code>tsconfig.json</code> are: Do you agree with my recommendations? Did I miss anything?</p>
21日前
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ヶ月前