2ality – JavaScript and more

フィード

記事のアイキャッチ画像
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>
6日前
記事のアイキャッチ画像
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>
7日前
記事のアイキャッチ画像
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>
22日前
記事のアイキャッチ画像
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>
1ヶ月前
記事のアイキャッチ画像
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>
2ヶ月前
記事のアイキャッチ画像
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>
2ヶ月前
記事のアイキャッチ画像
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>
2ヶ月前
記事のアイキャッチ画像
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>
2ヶ月前
記事のアイキャッチ画像
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>
2ヶ月前
記事のアイキャッチ画像
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>
2ヶ月前
記事のアイキャッチ画像
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>
2ヶ月前
記事のアイキャッチ画像
Array type notations: <code>T[]</code> vs. <code>Array&lt;T&gt;</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&lt;T&gt;</code>. I prefer the latter and will explain why.</p>
2ヶ月前
記事のアイキャッチ画像
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>
2ヶ月前
記事のアイキャッチ画像
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>
2ヶ月前
記事のアイキャッチ画像
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>
2ヶ月前
記事のアイキャッチ画像
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”&nbsp;to read up on them.</p>
2ヶ月前
記事のアイキャッチ画像
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>
2ヶ月前
記事のアイキャッチ画像
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>
2ヶ月前
記事のアイキャッチ画像
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>
2ヶ月前
記事のアイキャッチ画像
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&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>
3ヶ月前
記事のアイキャッチ画像
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>
3ヶ月前
記事のアイキャッチ画像
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>
3ヶ月前
記事のアイキャッチ画像
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>
3ヶ月前
記事のアイキャッチ画像
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>
3ヶ月前
記事のアイキャッチ画像
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>
3ヶ月前
記事のアイキャッチ画像
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>
3ヶ月前
記事のアイキャッチ画像
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>
3ヶ月前
記事のアイキャッチ画像
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>
4ヶ月前