Effective TypeScript

フィード

記事のアイキャッチ画像
The Making of a TypeScript Feature: Inferring Type Predicates
Effective TypeScript
<p>Over the past few months I became a TypeScript contributor and implemented a new feature, <a href="https://github.com/microsoft/TypeScript/pull/57465">type predicate inference</a>, that should be one of the headliners for TypeScript 5.5. This post tells the story of how that happened: why I wanted to contribute to TypeScript, the journey to implementing the feature and getting <a href="https://github.com/microsoft/TypeScript/pull/57465">the PR</a> merged, and what I&#39;ve learned along the way.</p><p>This is not a short read, but it will give you a good sense of what it&#39;s like to become a TypeScript contributor and develop a new feature.</p>
1ヶ月前
記事のアイキャッチ画像
Flow Nodes: How Type Inference Is Implemented
Effective TypeScript
<p>If a variable gets a type but no one looks at it, does it really get a type at all?</p><p>This post looks at how type inference is implemented in the TypeScript compiler. It's of some interest to anyone who uses TypeScript and is curious how it works, but it will be most relevant to developers who want to contribute to TypeScript itself.</p>
2ヶ月前
記事のアイキャッチ画像
The Hidden Side of Type Predicates
Effective TypeScript
Type guards are a powerful tool for improving TypeScript's built-in control flow analysis. This post looks at when it's appropriate to use a type predicate, and in particular what it means when a type predicate returns <code>false</code>.
3ヶ月前
記事のアイキャッチ画像
Effective TypeScript Talk at Etsy (Dec 2020)
Effective TypeScript
<p>Back in 2020 I gave a whole series of <a href="https://amzn.to/3HIrQN6"><em>Effective TypeScript</em></a> talks at companies that were interested in the language and the book. The talk that I gave at Etsy in December of 2020 was one of the most fun. It was recorded and is now available to watch. It&#39;s about an hour.</p>
4ヶ月前
記事のアイキャッチ画像
Don't Write Traditional Getter and Setter Methods in JavaScript and TypeScript
Effective TypeScript
<p>Getter and setter methods (<code>getFoo</code>, <code>setFoo</code>) are common in Java and considered a best practice. But they're a code smell that's best avoided in JavaScript and TypeScript because the problem they solve in Java does not exist in JS/TS. This post looks at what that problem is and how you can solve it in TypeScript without imposing the boilerplate of getters and setters.</p>
5ヶ月前
記事のアイキャッチ画像
Using infer to unpack nested types
Effective TypeScript
TypeScript's <code>infer</code> keyword can infer quite a bit more than you might expect. It's extremely effective at extracting types from the sort of nested structures that you might get from codegen or an API specification.
6ヶ月前
記事のアイキャッチ画像
Overload on the type of this to specialize generics (The Lost Item)
Effective TypeScript
I cut one item from Effective TypeScript during the final stages of editing. Four years later, it's time for it to see the light of day! It's a trick for specializing generic types for certain subtypes of their type parameters. This post shows how it works, why it's indispensible for wrapper types, and also explains why I cut it from the book.
7ヶ月前
記事のアイキャッチ画像
The Saga of the Closure Compiler, and Why TypeScript Won
Effective TypeScript
This post looks at the Closure Compiler, Google's tool from the mid-2000s for adding types to JavaScript. It looks at how its focus on minification led to very different design choices than TypeScript, and how this and a few other factors led to TypeScript becoming the ubiquitous solution for JavaScript + types. The Closure Compiler represents an alternative path that JavaScript could have taken, and it gives us perspective on TypeScript as it exists today.
8ヶ月前
記事のアイキャッチ画像
TypeScript and SQL: Six Ways to Bridge the Divide
Effective TypeScript
If you develop server code with TypeScript, you'll inevitably come up against the question of how to interact with your database. There's lots of type information in your database (the structure of the tables) and it's not immediately clear how to share that type information between the DB and TypeScript.This post and its accompanying video present six ways to solve this problem and offer some advice gleaned from years of experience combining Postgres and TypeScript.
9ヶ月前
記事のアイキャッチ画像
Recommendation Update: ✂️ Use knip to detect dead code and types
Effective TypeScript
<p>TL;DR: Use <a href="https://github.com/nadeesha/ts-prune">ts-prune</a> is in maintenance mode. Use <a href="https://github.com/webpro/knip">knip</a> to find dead code instead. It&#39;s great!</p>
10ヶ月前
記事のアイキャッチ画像
Notes on TypeScript 5.1
Effective TypeScript
<p>Every three months we get a new TypeScript release and <a href="https://devblogs.microsoft.com/typescript/announcing-typescript-5-1/">TypeScript 5.1</a> landed on June 1, 2023. This release has a few interesting new features, but by far the most noticeable changes are performance improvements and error message ergonomics. Let&#39;s take a look!</p>
1年前
記事のアイキャッチ画像
Item 30: Don’t Repeat Type Information in Documentation
Effective TypeScript
<p><em>Chapter 4 of <a href="https://amzn.to/3HIrQN6">Effective TypeScript</a> covers type design: the process of crafting your types to accurately model your domain. This item has always been a favorite of mine because of how immediately actionable it is. When you review code, be on the lookout for violations!</em></p><p>What’s wrong with this code?</p><figure class="highlight ts"><table><tr><td class="code"><pre><code class="hljs ts"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * Returns a string with the foreground color.</span><br><span class="hljs-comment"> * Takes zero or one arguments. With no arguments, returns the</span><br><span class="hljs-comment"> * standard foreground color. With one argument, returns the foreground color</span><br><span class="hljs-comment"> * for a particular page.</span><br><span class="hljs-comment"> */</span><br><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getForegroundColor<
1年前
記事のアイキャッチ画像
A first look at Deno through the Advent of Code 2022
Effective TypeScript
<p><img src="https://effectivetypescript.com/images/advent-of-code.png" title="Advent of Code Logo" width="64" height="64" style="float: right; margin-left: 10px;">Every year I do the <a href="https://adventofcode.com/">Advent of Code</a> in a different programming language. If you aren&#39;t familiar, it&#39;s an online coding competition with a new two-part problem every day from December 1st to the 25th. Thousands of programmers participate and share their solutions. It&#39;s a great way to learn a language and bond over coding. In <a href="https://danvdk.medium.com/python-tips-tricks-for-the-advent-of-code-2019-89ec23a595dd">2019</a> I used Python, in <a href="https://danvdk.medium.com/advent-of-code-2020-this-time-in-rust-7904559e24bc">2020</a> I used Rust and in <a href="https://effectivetypescript.com/2022/02/06/advent-of-code-2021-golang/">2021</a> I used Go. I also post an increasingly-belated writeup of my experience and impressions of the language so, at the end of April, h
1年前
記事のアイキャッチ画像
Notes on TypeScript 5.0 beta
Effective TypeScript
<p>TypeScript developers are a lucky bunch: for us, Christmas comes four times a year when the TypeScript team releases a new beta version. This is our opportunity to try out the latest features. <a href="https://devblogs.microsoft.com/typescript/announcing-typescript-5-0-beta/">TypeScript 5.0 beta</a> came out on January 26, 2023. Let&#39;s take a look at what&#39;s new!</p>
1年前
記事のアイキャッチ画像
All I Want for Christmas Is… These Seven TypeScript Improvements
Effective TypeScript
It's Christmastime and I've been happily working through this year's Advent of Code in Deno (look forward to a blog post in the new year). What with all the presents, it's a good time to think about what we'd most like to see from TypeScript in the new year. Here are my top seven feature requests for 2023. Yes, that's a lot, but really I'd be thrilled with just one or two. Pretty please?
1年前
記事のアイキャッチ画像
What's TypeScript compiling? Use a treemap to find out.
Effective TypeScript
Has TypeScript gotten slow for you? Run this one magic command to visualize what TypeScript is compiling, and maybe get to the root of the issue.
2年前
記事のアイキャッチ画像
A new way to test types
Effective TypeScript
Readers of Effective TypeScript and followers of this blog will know that testing types is a long-standing interest of mine. In this post I show how eslint-plugin-expect-type provides new syntax and tooling to make testing types so easy and fun that you'll <i>want</i> to do it!
2年前
記事のアイキャッチ画像
My Twitch Debut (eslint-plugin-expect-type with Josh Goldberg)
Effective TypeScript
<p><img src="https://effectivetypescript.com/images/twitch-screengrab.jpg" title="Screengrab from Twitch" width="320" height="180" style="float: right; margin-left: 10px;">I made my <a href="https://www.twitch.tv/videos/1455722291">Twitch debut</a> last week with <a href="https://twitter.com/JoshuaKGoldberg">Josh Goldberg</a>, who&#39;s writing O&#39;Reilly&#39;s upcoming <a href="https://learning.oreilly.com/library/view/learning-typescript/9781098110321/"><em>Learning TypeScript</em></a> title.</p><p>We talked through a <a href="https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type/pull/47">recent PR</a> I created to add TwoSlash support for Josh&#39;s expect-type eslint plugin. That syntax looks like this:</p><figure class="highlight ts"><table><tr><td class="code"><pre><code class="hljs ts"><span class="hljs-keyword">let</span> four = <span class="hljs-number">4</span>;<br><span class="hljs-comment">// ^? let four: number</span><br></code></pre></td></tr></table></figure>
2年前
記事のアイキャッチ画像
The display of types
Effective TypeScript
<p>We talk all the time about how to define and use types in TypeScript, but werarely talk about how TypeScript chooses to <i>display</i> our types. Thereare often several possible ways to display the same type, and the choice canhave a big impact on the usability of your library. TypeScript tries to makegood decisions on its own about type display, but it also gives us a few veryobscure levers by which we can control it ourselves.</p><p>Let's dive in to the strange world of type display!</p>
2年前
記事のアイキャッチ画像
A TypeScript Perspective on Go: the 2021 Advent of Code
Effective TypeScript
<p><img src="https://effectivetypescript.com/images/advent-of-code.png" title="Advent of Code Logo" width="64" height="64" style="float: right; margin-left: 10px;">It&#39;ll surprise no one to hear that TypeScript is my favorite programming language. But I do still enjoy dabbling in other languages. It&#39;s a great way to get perspective on what makes TypeScript unique, and how other language designers are thinking about the same problems.</p><p>My favorite way to learn a new language is through the annual <a href="https://adventofcode.com">Advent of Code</a> (AoC). AoC runs every year from Dec 1-25. Every day unlocks a new puzzle with two parts which build on each other. Lots of people do these puzzles (over 100,000 completed day 1 this year) and post their solutions on <a href="https://reddit.com/r/adventofcode">r/adventofcode</a>. In 2019 I <a href="https://danvdk.medium.com/python-tips-tricks-for-the-advent-of-code-2019-89ec23a595dd">did it in Python</a> (not a new language for m
2年前