<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Thomas Seeley</title><id>https://www.tseeley.com/atom.xml</id><updated>2026-01-15T00:00:00+00:00</updated><generator>tseeley.com</generator><link href="https://www.tseeley.com/atom.xml" rel="self" type="application/atom+xml"/><link href="https://www.tseeley.com" rel="alternate" type="text/html"/><subtitle>Posts about software and making things.</subtitle><entry><title>Nix Resources</title><id>https://www.tseeley.com/posts/nix-resources/</id><updated>2026-01-15T00:00:00+00:00</updated><author><name>Thomas Seeley</name></author><link href="https://www.tseeley.com/posts/nix-resources/" rel="alternate" type="text/html"/><published>2026-01-15T00:00:00+00:00</published><content type="html">
&lt;section id=&quot;Start-here&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Start-here&quot;&gt;Start here&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&quot;https://nix.dev&quot;&gt;nix.dev&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://nixos-and-flakes.thiscute.world/&quot;&gt;NixOS &amp;amp; Flakes
Book&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;Reference&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Reference&quot;&gt;Reference&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&quot;https://search.nixos.org&quot;&gt;search.nixos.org&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://noogle.dev&quot;&gt;noogle.dev&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://mynixos.com&quot;&gt;MyNixOS&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://home-manager-options.extranix.com/&quot;&gt;home-manager
options&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;Language-module-system&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Language-module-system&quot;&gt;Language + module system&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&quot;https://nixos.org/guides/nix-pills/&quot;&gt;Nix Pills&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://nix.dev/manual/nix/stable/&quot;&gt;Nix Reference Manual&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://nix.dev/tutorials/module-system/&quot;&gt;Module system
tutorial&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;Community&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Community&quot;&gt;Community&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&quot;https://discourse.nixos.org&quot;&gt;NixOS Discourse&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://wiki.nixos.org&quot;&gt;NixOS Wiki&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://reddit.com/r/NixOS&quot;&gt;r/NixOS&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;Code&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Code&quot;&gt;Code&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&quot;https://github.com/NixOS/nixpkgs&quot;&gt;nixpkgs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://github.com/Misterio77/nix-config&quot;&gt;Misterio77/nix-config&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://github.com/Mic92/dotfiles&quot;&gt;Mic92/dotfiles&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;

&lt;hr&gt;
&lt;p&gt;&lt;code&gt;nix&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.tseeley.com/about/&quot;&gt;Thomas Seeley&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://bsky.app/profile/tseeley.com&quot;&gt;@tseeley.com on Bluesky&lt;/a&gt;, &lt;a href=&quot;https://mastodon.social/@iamseeley&quot;&gt;@iamseeley on Mastodon&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.tseeley.com/posts/my-css-reset/&quot;&gt;My CSS Reset&lt;/a&gt; &amp;rarr;&lt;/p&gt;
</content></entry><entry><title>My CSS Reset</title><id>https://www.tseeley.com/posts/my-css-reset/</id><updated>2025-08-11T00:00:00+00:00</updated><author><name>Thomas Seeley</name></author><link href="https://www.tseeley.com/posts/my-css-reset/" rel="alternate" type="text/html"/><published>2025-08-11T00:00:00+00:00</published><content type="html">
&lt;pre data-lang=&quot;css&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#888888;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;,
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;*::&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;before,
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;*::&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;after &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;{
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;box-sizing&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;border-box&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;* {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;margin&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;body {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;line-height&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;1.5&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;,
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;,
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;textarea&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;,
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;select {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;font&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;inherit&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is the quick-and-dirty CSS reset I use to make my styles look more consistent across browsers. It serves as a nice starting point as I begin styling a new website.&lt;/p&gt;
&lt;p&gt;Inspired by &lt;a href=&quot;https://www.joshwcomeau.com/&quot;&gt;Josh Comeau’s&lt;/a&gt; &lt;a href=&quot;https://www.joshwcomeau.com/css/custom-css-reset/&quot;&gt;CSS reset&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;See the OG reset by Eric Meyer -&amp;gt; &lt;a href=&quot;https://meyerweb.com/eric/tools/css/reset/&quot;&gt;CSS Tools: Reset CSS&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;That’s all folks.&lt;/p&gt;

&lt;hr&gt;
&lt;p&gt;&lt;code&gt;css&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.tseeley.com/about/&quot;&gt;Thomas Seeley&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://bsky.app/profile/tseeley.com&quot;&gt;@tseeley.com on Bluesky&lt;/a&gt;, &lt;a href=&quot;https://mastodon.social/@iamseeley&quot;&gt;@iamseeley on Mastodon&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;larr; &lt;a href=&quot;https://www.tseeley.com/posts/nix-resources/&quot;&gt;Nix Resources&lt;/a&gt; · &lt;a href=&quot;https://www.tseeley.com/posts/onboarding/&quot;&gt;How To Onboard&lt;/a&gt; &amp;rarr;&lt;/p&gt;
</content></entry><entry><title>How To Onboard</title><id>https://www.tseeley.com/posts/onboarding/</id><updated>2025-08-05T00:00:00+00:00</updated><author><name>Thomas Seeley</name></author><link href="https://www.tseeley.com/posts/onboarding/" rel="alternate" type="text/html"/><published>2025-08-05T00:00:00+00:00</published><content type="html">
&lt;ol&gt;
&lt;li&gt;
Optimize for &lt;a href=&quot;https://en.wikipedia.org/wiki/Time_to_value&quot;&gt;time-to-value&lt;/a&gt;, not signup completion
&lt;/li&gt;
&lt;li&gt;
Never show a completely empty workspace
&lt;/li&gt;
&lt;li&gt;
Single, opinionated first action
&lt;/li&gt;
&lt;li&gt;
Personalize only when the answer changes the experience
&lt;/li&gt;
&lt;li&gt;
Teach by doing, not by tooltips
&lt;/li&gt;
&lt;li&gt;
Earn complexity over time
&lt;/li&gt;
&lt;li&gt;
Define and obsess over one activation milestone
&lt;/li&gt;
&lt;li&gt;
White-glove first to learn, then productize
&lt;/li&gt;
&lt;/ol&gt;

&lt;hr&gt;
&lt;p&gt;&lt;code&gt;ux&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.tseeley.com/about/&quot;&gt;Thomas Seeley&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://bsky.app/profile/tseeley.com&quot;&gt;@tseeley.com on Bluesky&lt;/a&gt;, &lt;a href=&quot;https://mastodon.social/@iamseeley&quot;&gt;@iamseeley on Mastodon&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;larr; &lt;a href=&quot;https://www.tseeley.com/posts/my-css-reset/&quot;&gt;My CSS Reset&lt;/a&gt; · &lt;a href=&quot;https://www.tseeley.com/posts/inferring-state-types/&quot;&gt;Inferring types from usage&lt;/a&gt; &amp;rarr;&lt;/p&gt;
</content></entry><entry><title>Inferring types from usage</title><id>https://www.tseeley.com/posts/inferring-state-types/</id><updated>2025-04-01T00:00:00+00:00</updated><author><name>Thomas Seeley</name></author><link href="https://www.tseeley.com/posts/inferring-state-types/" rel="alternate" type="text/html"/><published>2025-04-01T00:00:00+00:00</published><content type="html">
&lt;p&gt;Membrane programs have a &lt;a href=&quot;https://docs.membrane.io/guides/state&quot;&gt;persistent &lt;code&gt;state&lt;/code&gt; object&lt;/a&gt; that survives across deploys. You import it and use it like a regular JavaScript object:&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#888888;&quot;&gt;import { &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;state &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;} from &amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;membrane&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;count &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;??= &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;function increment&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;() {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return ++&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The entire JS heap is durable, but &lt;code&gt;state&lt;/code&gt; is the conventional way to pass data between code versions. The question is: what type is &lt;code&gt;state&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;We could make developers define a &lt;code&gt;State&lt;/code&gt; type for every program. But that’s boilerplate, and for quick scripts and prototypes it slows you down. We already had a TypeScript language service plugin for Membrane’s graph types, so I added state type inference to it.&lt;/p&gt;
&lt;section id=&quot;idea&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#idea&quot;&gt;The Idea&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;If you write &lt;code&gt;state.count ??= 0&lt;/code&gt;, we know &lt;code&gt;state.count&lt;/code&gt; is a &lt;code&gt;number&lt;/code&gt;. If you write &lt;code&gt;state.apiKey = args.apiKey&lt;/code&gt; and &lt;code&gt;args.apiKey&lt;/code&gt; is a &lt;code&gt;string&lt;/code&gt;, we know &lt;code&gt;state.apiKey&lt;/code&gt; is a &lt;code&gt;string&lt;/code&gt;. Walk the abstract syntax tree&lt;a id=&quot;fnref1&quot; href=&quot;#fn1&quot; role=&quot;doc-noteref&quot;&gt;&lt;sup&gt;1&lt;/sup&gt;&lt;/a&gt;, find every assignment to a &lt;code&gt;state&lt;/code&gt; property, extract the type from the right-hand side, and generate a type declaration.&lt;/p&gt;
&lt;p&gt;The generated type looks like this:&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;type State &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  count&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;number;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  apiKey&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;string;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;key: string&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;]: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;any;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;};
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That gets injected into the generated &lt;code&gt;membrane.d.ts&lt;/code&gt; file. You get autocomplete and type checking on &lt;code&gt;state&lt;/code&gt; without writing any type annotations. If you do want to define the type explicitly, export a &lt;code&gt;State&lt;/code&gt; type or interface from &lt;code&gt;index.ts&lt;/code&gt; and the inference backs off.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;tricky&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#tricky&quot;&gt;The Tricky Parts&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The idea is simple, but as always implementation had more edge cases than expected.&lt;/p&gt;
&lt;section id=&quot;Assignment-Patterns&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Assignment-Patterns&quot;&gt;Assignment Patterns&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Turns out people assign to &lt;code&gt;state&lt;/code&gt; in a lot of different ways:&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;count &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// direct assignment
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;count &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;??= &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// nullish coalescing assignment
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;count &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;||= &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// logical OR assignment
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;count &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;+= &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// compound assignment
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;count &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;value &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;as &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// type assertion
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The AST visitor needs to catch all of these. Direct assignments and compound assignments (&lt;code&gt;+=&lt;/code&gt;, &lt;code&gt;-=&lt;/code&gt;, etc.) fall in a range of operator token kinds between &lt;code&gt;FirstAssignment&lt;/code&gt; and &lt;code&gt;LastAssignment&lt;/code&gt;, which makes them easy to handle together. Nullish coalescing assignment (&lt;code&gt;??=&lt;/code&gt;) is its own token kind and needs a separate check:&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#888888;&quot;&gt;if (
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  ts&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;isBinaryExpression&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) &amp;amp;&amp;amp;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;operatorToken&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;kind &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;gt;= &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;ts&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;SyntaxKind&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;FirstAssignment &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;amp;&amp;amp;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;operatorToken&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;kind &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;lt;= &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;ts&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;SyntaxKind&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;LastAssignment
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  processStateAssignment&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;left&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;right&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;} else if (
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  ts&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;isBinaryExpression&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) &amp;amp;&amp;amp;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;operatorToken&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;kind &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;=== &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;ts&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;SyntaxKind&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;QuestionQuestionEqualsToken
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  processStateAssignment&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;left&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;right&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/section&gt;
&lt;section id=&quot;Nullish-Coalescing-and-any&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Nullish-Coalescing-and-any&quot;&gt;Nullish Coalescing and &lt;code&gt;any&lt;/code&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;state.count ??= 0&lt;/code&gt; is interesting because the right-hand side is a binary expression with &lt;code&gt;??&lt;/code&gt;. The left side is &lt;code&gt;state.count&lt;/code&gt;, which might be &lt;code&gt;any&lt;/code&gt; if we haven’t inferred a type for it yet. The right side is &lt;code&gt;0&lt;/code&gt;, which is &lt;code&gt;number&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If we naively get the type of the whole expression, TypeScript might give us &lt;code&gt;any&lt;/code&gt; because one side is &lt;code&gt;any&lt;/code&gt;. So we check both sides individually:&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#888888;&quot;&gt;if (
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;operatorToken&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;kind &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;=== &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;ts&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;SyntaxKind&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;QuestionQuestionToken &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;||
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;operatorToken&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;kind &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;=== &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;ts&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;SyntaxKind&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;BarBarToken
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;leftType &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;checker&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;getTypeAtLocation&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;left&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;rightType &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;checker&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;getTypeAtLocation&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;right&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;isLeftAny &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= (&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;leftType&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;getFlags&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;() &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;ts&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;TypeFlags&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;Any&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) !== &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;isRightAny &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= (&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;rightType&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;getFlags&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;() &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;ts&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;TypeFlags&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;Any&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) !== &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;if (&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;isLeftAny &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;amp;&amp;amp; !&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;isRightAny&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) return &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;rightType&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;if (!&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;isLeftAny &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;isRightAny&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) return &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;leftType&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;checker&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;getTypeAtLocation&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If one side is &lt;code&gt;any&lt;/code&gt; and the other is concrete, use the concrete type. If both are concrete, use the union. This is what makes &lt;code&gt;state.count ??= 0&lt;/code&gt; correctly infer &lt;code&gt;number&lt;/code&gt; instead of &lt;code&gt;any&lt;/code&gt;.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;Explicit-vs-Inferred-Priority&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Explicit-vs-Inferred-Priority&quot;&gt;Explicit vs Inferred Priority&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Consider this:&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;count &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;??= &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// inferred: number
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;count &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;getCount&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(); &lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// explicit: number (from getCount&amp;#39;s return type)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Both assignments tell us &lt;code&gt;state.count&lt;/code&gt; is a &lt;code&gt;number&lt;/code&gt;, but they have different confidence levels. A direct assignment (&lt;code&gt;=&lt;/code&gt;) is explicit. A nullish coalescing assignment (&lt;code&gt;??=&lt;/code&gt;) or logical OR assignment (&lt;code&gt;||=&lt;/code&gt;) is inferred, because they’re fallback patterns that might not represent the primary type.&lt;/p&gt;
&lt;p&gt;When we see a new assignment to a property we’ve already typed, explicit assignments override inferred ones. More specific types override &lt;code&gt;any&lt;/code&gt;. This means the order of assignments in your code doesn’t matter as much as the kind of assignment.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;Type-Assertions&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Type-Assertions&quot;&gt;Type Assertions&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;If you write &lt;code&gt;state.data = response as ApiResponse&lt;/code&gt;, the type should be &lt;code&gt;ApiResponse&lt;/code&gt;, not whatever TypeScript infers from &lt;code&gt;response&lt;/code&gt;. The plugin checks for &lt;code&gt;as&lt;/code&gt; expressions and type assertion expressions, unwrapping parenthesized expressions along the way:&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#888888;&quot;&gt;function &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;getAssertedType&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(node&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;Expression)&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;: Type &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;| &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;undefined &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;{
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;if (&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;ts&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;isAsExpression&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) || &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;ts&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;isTypeAssertionExpression&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;)) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;checker&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;getTypeAtLocation&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;if (&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;ts&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;isParenthesizedExpression&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;)) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;getAssertedType&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;expression&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// ...
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/section&gt;
&lt;/section&gt;
&lt;section id=&quot;assembly&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#assembly&quot;&gt;How It Fits Together&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The inference hooks into &lt;code&gt;getSemanticDiagnostics&lt;/code&gt;. Every time the editor updates diagnostics, the plugin walks the AST, collects &lt;code&gt;state&lt;/code&gt; assignments, and generates the &lt;code&gt;State&lt;/code&gt; type string. If it changed since last time, &lt;code&gt;membrane.d.ts&lt;/code&gt; gets regenerated.&lt;/p&gt;
&lt;p&gt;If a developer exports their own &lt;code&gt;State&lt;/code&gt; type:&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;interface State &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;{
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  count&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  apiKey&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The plugin detects that and imports it instead of generating one. Explicit always wins.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;general&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#general&quot;&gt;The General Problem&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The technique here isn’t specific to state. It’s a general approach: infer the type of an untyped object by walking all the places it’s assigned to across a codebase. You could apply the same pattern to config objects, environment variables, feature flags, or any global singleton that accumulates properties over time.&lt;/p&gt;
&lt;p&gt;TypeScript itself has &lt;a href=&quot;https://github.com/microsoft/TypeScript/issues/34738&quot;&gt;open issues&lt;/a&gt; requesting “infer type from usage” for implicit &lt;code&gt;any&lt;/code&gt; parameters, but it’s scoped to a single function body, not whole-program analysis. &lt;a href=&quot;https://flow.org/&quot;&gt;Flow&lt;/a&gt; does whole-program type inference, but that’s an entire type system. &lt;a href=&quot;https://github.com/JoshuaKGoldberg/TypeStat&quot;&gt;TypeStat&lt;/a&gt; infers types from usage patterns and writes annotations back into source files, but it targets individual variables and parameters, not a shared object.&lt;/p&gt;
&lt;p&gt;The architecture closest to ours is &lt;a href=&quot;https://github.com/vuejs/language-tools&quot;&gt;Volar&lt;/a&gt; (Vue Language Tools), which generates virtual TypeScript files from &lt;code&gt;.vue&lt;/code&gt; single-file components. The pattern is the same: take a non-standard source of type information, generate a &lt;code&gt;.d.ts&lt;/code&gt; that the TypeScript language service can understand, and keep it updated as the source changes.&lt;/p&gt;
&lt;p&gt;We’re doing a narrower version of that. Walk assignments to one object, build a type from what we find, inject it into a generated declaration file.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;takeaways&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#takeaways&quot;&gt;What I Learned&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Working on this gave me a better feel for &lt;a href=&quot;https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API&quot;&gt;TypeScript’s compiler API&lt;/a&gt; than anything else I’ve done. The &lt;code&gt;TypeChecker&lt;/code&gt; is powerful but not always intuitive. &lt;code&gt;getTypeAtLocation&lt;/code&gt; can return &lt;code&gt;any&lt;/code&gt; in cases where you’d expect something more specific, especially when the thing you’re checking is a property of an untyped object (which &lt;code&gt;state&lt;/code&gt; is, until we infer its type). The &lt;code&gt;getBaseTypeOfLiteralType&lt;/code&gt; call is important too. Without it, &lt;code&gt;state.count = 0&lt;/code&gt; would infer the literal type &lt;code&gt;0&lt;/code&gt; instead of &lt;code&gt;number&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The biggest takeaway: type inference is a game of priorities! You have multiple sources of type information (direct assignments, fallback patterns, type assertions, compound assignments) and you need rules for which one wins. Getting those priority rules right is what makes the experience feel natural instead of surprising.&lt;/p&gt;
&lt;/section&gt;
&lt;section role=&quot;doc-endnotes&quot;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&quot;fn1&quot;&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Abstract_syntax_tree&quot;&gt;Abstract Syntax Tree&lt;/a&gt;, a tree representation of source code structure.&lt;a href=&quot;#fnref1&quot; role=&quot;doc-backlink&quot;&gt;↩︎&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;

&lt;hr&gt;
&lt;p&gt;&lt;code&gt;typescript&lt;/code&gt; &lt;code&gt;membrane&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.tseeley.com/about/&quot;&gt;Thomas Seeley&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://bsky.app/profile/tseeley.com&quot;&gt;@tseeley.com on Bluesky&lt;/a&gt;, &lt;a href=&quot;https://mastodon.social/@iamseeley&quot;&gt;@iamseeley on Mastodon&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;larr; &lt;a href=&quot;https://www.tseeley.com/posts/onboarding/&quot;&gt;How To Onboard&lt;/a&gt; · &lt;a href=&quot;https://www.tseeley.com/posts/we-forked-typescript/&quot;&gt;We forked TypeScript&lt;/a&gt; &amp;rarr;&lt;/p&gt;
</content></entry><entry><title>We forked TypeScript</title><id>https://www.tseeley.com/posts/we-forked-typescript/</id><updated>2025-03-10T00:00:00+00:00</updated><author><name>Thomas Seeley</name></author><link href="https://www.tseeley.com/posts/we-forked-typescript/" rel="alternate" type="text/html"/><published>2025-03-10T00:00:00+00:00</published><content type="html">
&lt;p&gt;At &lt;a href=&quot;https://membrane.io&quot;&gt;Membrane&lt;/a&gt;, we forked TypeScript to extend contextual typing so our programming model gets type inference for free.&lt;/p&gt;
&lt;p&gt;The changes were made by &lt;a href=&quot;https://x.com/juancampa&quot;&gt;Juan Campa&lt;/a&gt;. I went through them recently while updating our fork to the latest TypeScript version. What I found was surprisingly small and worth explaining.&lt;/p&gt;
&lt;section id=&quot;What-Is-Contextual-Typing&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#What-Is-Contextual-Typing&quot;&gt;What Is Contextual Typing&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Most type inference works bottom-up. You write &lt;code&gt;let x = 42&lt;/code&gt; and the compiler infers &lt;code&gt;number&lt;/code&gt; from the value. &lt;a href=&quot;https://www.typescriptlang.org/docs/handbook/type-inference.html#contextual-typing&quot;&gt;Contextual typing&lt;/a&gt; works top-down. The compiler looks at where an expression appears and infers types from the surrounding context.&lt;/p&gt;
&lt;p&gt;You’ve seen this in TypeScript even if you didn’t know the name:&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// TypeScript knows `e` is MouseEvent from addEventListener&amp;#39;s signature
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;window.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;click&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;, (e) =&amp;gt; {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;clientX&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;});
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// TypeScript knows `x` is a string from the array type
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;[&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;].&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;((x) =&amp;gt; &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;toUpperCase&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;());
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The type flows down from the context into the expression. You don’t annotate the callback parameters because the compiler already knows what they should be.&lt;/p&gt;
&lt;p&gt;This isn’t unique to TypeScript. &lt;a href=&quot;https://docs.swift.org/swift-book/documentation/the-swift-programming-language/closures/&quot;&gt;Swift&lt;/a&gt; does it for closures. &lt;a href=&quot;https://kotlinlang.org/docs/lambdas.html&quot;&gt;Kotlin&lt;/a&gt; infers lambda parameter types from the expected function type. &lt;a href=&quot;https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/new-operator#target-typed-new&quot;&gt;C#&lt;/a&gt; has target-typed &lt;code&gt;new&lt;/code&gt; expressions and lambda inference. Scala has its own flavor called “colored local type inference.” The theoretical foundation is &lt;a href=&quot;https://arxiv.org/abs/1908.05839&quot;&gt;bidirectional typing&lt;/a&gt;, which combines bottom-up synthesis with top-down checking.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;Where-TypeScripts-Contextual-Typing-Stops&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Where-TypeScripts-Contextual-Typing-Stops&quot;&gt;Where TypeScript’s Contextual Typing Stops&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Contextual typing in TypeScript works for callbacks, assignment right-hand sides, object literal members, array elements, and return statements. It does not work for top-level exported function declarations or variable declarations against an external type.&lt;/p&gt;
&lt;p&gt;This means if you have a type somewhere that describes the shape of a function, and you write a top-level &lt;code&gt;export function&lt;/code&gt; that should match it, TypeScript won’t infer the parameter types. You have to annotate them manually.&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// These types exist somewhere
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;type ConfigureArgs &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= { &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;schema&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;Schema &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;};
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;Configure &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= (args&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;ConfigureArgs) =&amp;gt; void;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// TypeScript does NOT infer `args` here
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;function configure&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;args&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// args is implicitly `any`
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// You have to do this instead
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;function configure&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;args: ConfigureArgs&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// now args is typed
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For most codebases this is fine. For Membrane, it’s the core of the developer experience.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;Membranes-Programming-Model&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Membranes-Programming-Model&quot;&gt;Membrane’s Programming Model&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Membrane programs are durable TypeScript programs that expose their data and functionality through a &lt;a href=&quot;https://docs.membrane.io/concepts/the-graph&quot;&gt;type-safe graph&lt;/a&gt;. Each program has a schema (defined in &lt;code&gt;memconfig.json&lt;/code&gt;) that declares its node types with fields, actions, and events. Think of it like a GraphQL schema for your program’s API.&lt;/p&gt;
&lt;p&gt;Every program has an &lt;code&gt;index.ts&lt;/code&gt; that exports &lt;strong&gt;&lt;strong&gt;resolvers&lt;/strong&gt;&lt;/strong&gt;: functions and objects that implement the schema. When someone queries a node in the graph, Membrane invokes the corresponding resolver to produce the value.&lt;/p&gt;
&lt;p&gt;A typical &lt;code&gt;index.ts&lt;/code&gt; looks like this:&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#888888;&quot;&gt;import { &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;nodes&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;root &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;} from &amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;membrane&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;Root &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;status&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;() {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return &amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;ready&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;},
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  configure&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;,
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;emails&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: () =&amp;gt; ({}),
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;};
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;EmailCollection &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;async one&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;({ id }) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;await api&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;GET&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;, `&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;emails/&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;${&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}`);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;},
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;async page&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;() {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;result &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;await api&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;GET&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;emails&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return { &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;items&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;result&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;data &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;};
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;},
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;};
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;Email &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;gref&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(_, { obj }) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return root.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;emails&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;one&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;({ &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;id &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;});
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;},
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;async cancel&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(_, { self }) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const { &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;id &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;} = self.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;$argsAt&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(root.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;emails&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;one&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;api&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;POST&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;, `&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;emails/&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;${&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;/cancel&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;`);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;},
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;};
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Every one of those exported objects and functions needs to match the schema’s type definitions. The types are generated into a &lt;code&gt;membrane.d.ts&lt;/code&gt; file and live in a global &lt;code&gt;resolvers&lt;/code&gt; namespace. Without the fork, every resolver would need explicit type annotations. With dozens of resolvers per program, that’s a lot of boilerplate. And if the schema changes, every annotation needs updating.&lt;/p&gt;
&lt;p&gt;We wanted the types to flow automatically: define the schema once, and the implementations get typed from context.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;The-Fork&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#The-Fork&quot;&gt;The Fork&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The entire fork is about 70 lines of changes in &lt;code&gt;src/compiler/checker.ts&lt;/code&gt;. No parser changes, no new syntax, no emitter modifications. Three commits, all by Juan.&lt;/p&gt;
&lt;p&gt;The changes do three things:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;1. Identify Membrane resolvers.&lt;/strong&gt;&lt;/strong&gt; Three helper functions check whether a declaration is an exported, top-level, named function or variable in an &lt;code&gt;index.ts&lt;/code&gt; file:&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#888888;&quot;&gt;function &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;isMembraneFunctionResolver&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(node&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;FunctionDeclaration) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return (
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    isInIndexTs&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) &amp;amp;&amp;amp;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    isInTopLevelContext&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) &amp;amp;&amp;amp;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    hasSyntacticModifier&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;ModifierFlags&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;Export&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) &amp;amp;&amp;amp;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;name &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;amp;&amp;amp;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    isIdentifier&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;function &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;isInIndexTs&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(node&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;Node)&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;: boolean &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;{
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;sourceFile &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;getSourceFileOfNode&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;node&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return !!&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;sourceFile &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;amp;&amp;amp; /&lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;\/&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;[^&lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;]+&lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;\/index\.ts&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;$/.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;sourceFile&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;fileName&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;2. Look up the contextual type.&lt;/strong&gt;&lt;/strong&gt; When the checker encounters a qualifying declaration, it looks up the function or variable name in the global &lt;code&gt;resolvers&lt;/code&gt; namespace and uses the matching type:&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// For variable declarations like: export const Root = { ... }
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;ns &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;globals&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;escapeLeadingUnderscores&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;resolvers&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;));
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const exports = &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;ns &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;getExportsOfSymbol&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;ns&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;exportSymbol &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= exports?.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;declaration&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;escapedText&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;typeAlias &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;exportSymbol &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;exportSymbol&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;declarations&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;![&lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;];
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;type &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;typeAlias &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;getTypeFromTypeNode&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;typeAlias&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;3. Mark exported functions as context-sensitive.&lt;/strong&gt;&lt;/strong&gt; Standard TypeScript only considers function expressions, arrow functions, and object literal methods as context-sensitive. The fork adds exported functions in &lt;code&gt;index.ts&lt;/code&gt; to that set, which is what makes the checker attempt contextual typing for them at all:&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#888888;&quot;&gt;function &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;isContextSensitiveFunctionOrObjectLiteralMethod&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(func) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;isMembraneExport &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;=
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    hasSyntacticModifier&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;ModifierFlags&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;Export&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) &amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;isInIndexTs&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return (
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    isMembraneExport &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;||
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;isFunctionExpressionOrArrowFunction&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) ||
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;      isObjectLiteralMethod&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;)) &amp;amp;&amp;amp;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;      isContextSensitiveFunctionLikeDeclaration&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;))
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That’s it. If there’s no global &lt;code&gt;resolvers&lt;/code&gt; namespace, all the guards return early and standard TypeScript behavior applies. The changes are purely additive.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;What-It-Looks-Like&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#What-It-Looks-Like&quot;&gt;What It Looks Like&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Before the fork, a Membrane &lt;code&gt;index.ts&lt;/code&gt; would need explicit annotations everywhere:&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#888888;&quot;&gt;import { &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;nodes&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;root &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;} from &amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;membrane&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;function configure&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;args: ConfigureArgs&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;void {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  state.apiKey = args.apiKey;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;Root: RootResolvers &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;status&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(): &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;string {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    return state.apiKey ? &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;ready&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot; : &amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;not configured&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;},
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  emails: &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;() =&amp;gt; ({}),
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;EmailCollection: EmailCollectionResolvers &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;async one&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;({ id }&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;{ id&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;string }) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;await api&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;GET&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;, `&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;emails/&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;${&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}`);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;},
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;};
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;Email: EmailResolvers &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;gref&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(_, { obj }&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;{ obj&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;any }) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return root.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;emails&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;one&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;({ &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;id &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;});
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;},
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;};
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After the fork:&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#888888;&quot;&gt;import { &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;nodes&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;root &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;} from &amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;membrane&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;function configure&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;args&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  state&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;apiKey &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;args&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;apiKey&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;Root &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;status&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;() {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;apiKey &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;? &amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;ready&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot; : &amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;not configured&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;},
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;emails&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: () =&amp;gt; ({}),
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;};
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;EmailCollection &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;async one&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;({ id }) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;await api&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;GET&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;, `&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;emails/&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;${&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}`);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;},
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;};
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;Email &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;gref&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(_, { obj }) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;return root.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;emails&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;one&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;({ &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;id &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;});
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;},
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;};
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Same code, no annotations. The types are inferred from the schema. You get autocomplete, error checking, and hover information. If the schema changes (say you add a &lt;code&gt;subject&lt;/code&gt; field to &lt;code&gt;Email&lt;/code&gt;), the resolver types update automatically. No manual syncing.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;Why-Fork-Instead-of&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Why-Fork-Instead-of&quot;&gt;Why Fork Instead of…&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The obvious question: why not use &lt;code&gt;satisfies&lt;/code&gt;, explicit annotations, or a code generation step?&lt;/p&gt;
&lt;p&gt;&lt;code&gt;satisfies&lt;/code&gt; works for objects (&lt;code&gt;export const Root = { ... } satisfies RootResolvers&lt;/code&gt;) but not for function declarations. It also requires the developer to remember to add it. We wanted types to flow automatically from the schema with no ceremony.&lt;/p&gt;
&lt;p&gt;Code generation (generating annotated stubs from the schema) adds a build step and creates files the developer has to maintain alongside the schema. We wanted the source of truth to be the schema alone.&lt;/p&gt;
&lt;p&gt;A TypeScript language service plugin could provide autocomplete but can’t add real type checking. We wanted both.&lt;/p&gt;
&lt;p&gt;Forking the compiler was the cleanest path. ~70 lines, scoped to &lt;code&gt;index.ts&lt;/code&gt; files in the presence of a &lt;code&gt;resolvers&lt;/code&gt; namespace, no impact on non-Membrane code. The tradeoff is maintaining the fork across TypeScript releases, which is what I was doing when I decided to write this post.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;Maintaining-the-Fork&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Maintaining-the-Fork&quot;&gt;Maintaining the Fork&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Updating the fork means rebasing our changes onto the latest TypeScript release. Since the changes are small and concentrated in one file, this has been straightforward so far. The checker’s internal API does change between versions, so some adaptation is needed, but the core pattern (look up a name in a namespace, return its type) stays stable.&lt;/p&gt;
&lt;p&gt;The bigger risk is if TypeScript ever adds native support for this kind of module-level contextual typing. That would be great, actually. We’d happily drop the fork. There are &lt;a href=&quot;https://github.com/microsoft/TypeScript/issues/53701&quot;&gt;open issues&lt;/a&gt; requesting more contextual typing for function return values, and the general direction of TypeScript’s inference has been to expand where context flows. But top-level declarations against a global type namespace isn’t on the roadmap as far as I know.&lt;/p&gt;
&lt;p&gt;Until then, ~70 lines in the checker gets us what we need.&lt;/p&gt;
&lt;/section&gt;

&lt;hr&gt;
&lt;p&gt;&lt;code&gt;typescript&lt;/code&gt; &lt;code&gt;membrane&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.tseeley.com/about/&quot;&gt;Thomas Seeley&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://bsky.app/profile/tseeley.com&quot;&gt;@tseeley.com on Bluesky&lt;/a&gt;, &lt;a href=&quot;https://mastodon.social/@iamseeley&quot;&gt;@iamseeley on Mastodon&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;larr; &lt;a href=&quot;https://www.tseeley.com/posts/inferring-state-types/&quot;&gt;Inferring types from usage&lt;/a&gt; · &lt;a href=&quot;https://www.tseeley.com/posts/how-to-use-chrome-devtools/&quot;&gt;How to Use Chrome DevTools&lt;/a&gt; &amp;rarr;&lt;/p&gt;
</content></entry><entry><title>How to Use Chrome DevTools</title><id>https://www.tseeley.com/posts/how-to-use-chrome-devtools/</id><updated>2024-12-15T00:00:00+00:00</updated><author><name>Thomas Seeley</name></author><link href="https://www.tseeley.com/posts/how-to-use-chrome-devtools/" rel="alternate" type="text/html"/><published>2024-12-15T00:00:00+00:00</published><content type="html">
&lt;p&gt;I’ve been using DevTools for a while, but I often feel like I don’t really &lt;em&gt;know&lt;/em&gt; how to use all the tools. Or even all the tools that actually exist (there’s a lot)!&lt;/p&gt;
&lt;p&gt;Everything here is something I use already or wish I’d known about sooner. It’s mostly organized by what you’re trying to do, not by which panel it’s in.&lt;/p&gt;
&lt;section id=&quot;Getting-Around&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Getting-Around&quot;&gt;Getting Around&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Command Menu.&lt;/strong&gt;&lt;/strong&gt; &lt;code&gt;Cmd + Shift + P&lt;/code&gt; opens it. It works like the &lt;a href=&quot;https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette&quot;&gt;VS Code command palette&lt;/a&gt;. Type what you want to do and it’ll find it.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&quot;command-menu.png&quot; alt=&quot;The Command Menu&quot;&gt;
  &lt;figcaption&gt;The &lt;a href=&quot;https://developer.chrome.com/docs/devtools/command-menu&quot;&gt;Command Menu&lt;/a&gt;. &lt;code&gt;Cmd + Shift + P&lt;/code&gt; to open.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/open#files&quot;&gt;Quick open&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; &lt;code&gt;Cmd + P&lt;/code&gt; opens any file loaded by the page. If you know the filename you’re looking for, this is faster than navigating the Sources tree.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Switch panels.&lt;/strong&gt;&lt;/strong&gt; &lt;code&gt;Cmd + ]&lt;/code&gt; and &lt;code&gt;Cmd + [&lt;/code&gt; move between panels. &lt;code&gt;Cmd + Shift + J&lt;/code&gt; goes straight to Console. &lt;code&gt;Cmd + Shift + C&lt;/code&gt; goes straight to element inspection mode.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/search&quot;&gt;Search across all files&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; &lt;code&gt;Cmd + Option + F&lt;/code&gt; searches every file loaded by the page. Useful for finding where a string, class name, or function is defined when you don’t know which file it’s in.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;Elements-and-CSS&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Elements-and-CSS&quot;&gt;Elements and CSS&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Inspect.&lt;/strong&gt;&lt;/strong&gt; &lt;code&gt;Cmd + Shift + C&lt;/code&gt; activates the selector, then click any element. Or right-click anything on the page and hit Inspect. You probably know this one.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Force element state.&lt;/strong&gt;&lt;/strong&gt; Select an element, click the &lt;code&gt;:hov&lt;/code&gt; button in the Styles tab, and check &lt;code&gt;:hover&lt;/code&gt;, &lt;code&gt;:active&lt;/code&gt;, &lt;code&gt;:focus&lt;/code&gt;, or &lt;code&gt;:focus-within&lt;/code&gt;. The element stays in that state so you can inspect the styles without trying to keep your mouse in the right spot.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&quot;force-state.png&quot; alt=&quot;Force element state panel&quot;&gt;
  &lt;figcaption&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/css/reference#force-state&quot;&gt;Force element state&lt;/a&gt;. Lock &lt;code&gt;:hover&lt;/code&gt;, &lt;code&gt;:active&lt;/code&gt;, &lt;code&gt;:focus&lt;/code&gt; without holding the mouse.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/dom&quot;&gt;Edit HTML live&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Double-click any element in the Elements panel to edit its HTML. You can change text, attributes, add elements, whatever. Changes show up immediately.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/css/reference#change-declaration&quot;&gt;Edit CSS live&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Click any CSS value in the Styles panel to change it. Click the property name to change that too. Add new properties by clicking the empty space at the bottom of a rule. Toggle any property on/off with the checkbox next to it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/css/reference#add-class&quot;&gt;Add a class&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; The &lt;code&gt;.cls&lt;/code&gt; button in the Styles panel lets you add or remove CSS classes from the selected element. Faster than editing the &lt;code&gt;class&lt;/code&gt; attribute by hand.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/css/reference#computed&quot;&gt;See computed styles&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; The Computed tab shows every CSS property actually applied to the element after cascade, inheritance, and specificity resolve. Click the arrow next to any property to jump to the rule that set it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;CSS specificity.&lt;/strong&gt;&lt;/strong&gt; Hover over a selector in the Styles tab to see its specificity score.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Box model.&lt;/strong&gt;&lt;/strong&gt; The box model diagram at the bottom of the Styles tab (or top of Computed) is interactive. Double-click any value to change margin, padding, border, or dimensions.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&quot;box-model.png&quot; alt=&quot;The box model diagram&quot;&gt;
  &lt;figcaption&gt;The interactive &lt;a href=&quot;https://developer.chrome.com/docs/devtools/css/reference#box-model&quot;&gt;box model&lt;/a&gt;. Double-click any value to edit it.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Find unused CSS.&lt;/strong&gt;&lt;/strong&gt; &lt;code&gt;Cmd + Shift + P&lt;/code&gt;, type “Coverage”, click record, interact with the page. Red bars mean unused code, green means used. This tells you how much CSS (and JS) the page loads but never runs.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&quot;coverage.png&quot; alt=&quot;Coverage panel showing used and unused code&quot;&gt;
  &lt;figcaption&gt;The &lt;a href=&quot;https://developer.chrome.com/docs/devtools/coverage&quot;&gt;Coverage panel&lt;/a&gt;. Red is unused, green is used.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/css/color&quot;&gt;Colors&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Click any color swatch in the Styles panel to get a visual color picker. You can switch between hex, rgb, and hsl.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Drag and reorder.&lt;/strong&gt;&lt;/strong&gt; You can drag elements in the DOM tree to reorder them. Useful for testing layout changes without editing code.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;Console&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Console&quot;&gt;Console&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;code&gt;$0&lt;/code&gt; through &lt;code&gt;$4&lt;/code&gt;.&lt;/strong&gt;&lt;/strong&gt; &lt;code&gt;$0&lt;/code&gt; in the console references whatever element you have selected in the Elements panel. &lt;code&gt;$1&lt;/code&gt; is the previously selected element, and so on. I use &lt;code&gt;$0&lt;/code&gt; constantly.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&quot;console-dollar-zero.png&quot; alt=&quot;Using $0 in the console&quot;&gt;
  &lt;figcaption&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/console/utilities#dom&quot;&gt;&lt;code&gt;$0&lt;/code&gt;&lt;/a&gt; references the currently selected element.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/console/utilities#querySelector&quot;&gt;&lt;code&gt;$(&apos;selector&apos;)&lt;/code&gt; and &lt;code&gt;$$(&apos;selector&apos;)&lt;/code&gt;&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Shortcuts for &lt;code&gt;document.querySelector&lt;/code&gt; and &lt;code&gt;document.querySelectorAll&lt;/code&gt;. Only work in the console, not in page scripts.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/console/api#table&quot;&gt;&lt;code&gt;console.table()&lt;/code&gt;&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Pass it an array of objects and it renders a sortable table. Way more readable than logging an array.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/console/api#time&quot;&gt;&lt;code&gt;console.time()&lt;/code&gt; / &lt;code&gt;console.timeEnd()&lt;/code&gt;&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Wrap code between &lt;code&gt;console.time(&apos;label&apos;)&lt;/code&gt; and &lt;code&gt;console.timeEnd(&apos;label&apos;)&lt;/code&gt; to measure how long it takes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/console/api#group&quot;&gt;&lt;code&gt;console.group()&lt;/code&gt; / &lt;code&gt;console.groupEnd()&lt;/code&gt;&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Creates collapsible groups in the console output. Useful for organizing noisy logging.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/console/api#trace&quot;&gt;&lt;code&gt;console.trace()&lt;/code&gt;&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Logs a stack trace at whatever point you call it. Helpful for figuring out where a function is being called from.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/console/utilities#monitor&quot;&gt;&lt;code&gt;monitor(fn)&lt;/code&gt;&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Logs every time a function is called, with its arguments. &lt;code&gt;unmonitor(fn)&lt;/code&gt; to stop. Only works for functions in global scope.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/console/utilities#copy&quot;&gt;Copy an object&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; &lt;code&gt;copy(obj)&lt;/code&gt; copies any JavaScript object to your clipboard as JSON. This one is easy to forget about.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Filter messages.&lt;/strong&gt;&lt;/strong&gt; The filter bar at the top of the Console panel lets you filter by text, by level (errors, warnings, info), or by source. The “Selected context only” dropdown filters to the current iframe or worker.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/console/reference#persist&quot;&gt;Preserve log&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Check “Preserve log” in Console settings to keep messages across page reloads. Invaluable when debugging redirect flows or page initialization.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;Debugging-JavaScript&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Debugging-JavaScript&quot;&gt;Debugging JavaScript&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/javascript/breakpoints#loc&quot;&gt;Set a breakpoint&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Sources panel, click a line number. The blue marker means execution will pause there. Click it again to remove it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Conditional breakpoints.&lt;/strong&gt;&lt;/strong&gt; Right-click a line number, choose “Add conditional breakpoint,” enter a condition like &lt;code&gt;x &amp;gt; 10&lt;/code&gt;. Execution only pauses when the condition is true. Saves you from stepping through irrelevant iterations.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&quot;conditional-breakpoint.png&quot; alt=&quot;A conditional breakpoint&quot;&gt;
  &lt;figcaption&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/javascript/breakpoints#conditional-loc&quot;&gt;Conditional breakpoints&lt;/a&gt;. Only pauses when your expression is true.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/javascript/breakpoints#exceptions&quot;&gt;Pause on exceptions&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; The pause icon in the Sources panel has a toggle for pausing on all exceptions or only uncaught ones. Useful for catching errors the moment they happen instead of hunting through the call stack.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/javascript/reference#stepping&quot;&gt;Step through code&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Once paused:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;F10&lt;/code&gt; (step over) executes the current line and moves to the next
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;F11&lt;/code&gt; (step into) enters the function being called
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Shift + F11&lt;/code&gt; (step out) runs to the end of the current function and pauses in the caller
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;F8&lt;/code&gt; resumes execution
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/javascript/reference#watch&quot;&gt;Watch expressions&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; In the Sources panel sidebar, add expressions to the Watch section. They update every time execution pauses. Useful for tracking a variable across multiple breakpoints.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/javascript/reference#scope&quot;&gt;Local variables&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; The Scope section in the Sources panel shows every variable in scope when execution is paused. Local, closure, and global scopes are all visible.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/javascript/reference#format&quot;&gt;Pretty print&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Click the &lt;code&gt;{}&lt;/code&gt; icon at the bottom of any minified file to format it. Makes third-party code readable enough to set breakpoints in.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/javascript/reference#ignore-list&quot;&gt;Blackbox scripts&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Right-click a script in the Sources panel and choose “Add script to ignore list.” The debugger will skip over it when stepping. Useful for skipping framework internals.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/dom#event-listeners&quot;&gt;Debug event listeners&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Elements panel, select an element, expand the “Event Listeners” tab. Shows every listener attached, with a link to the handler source. Check “Ancestors” to see listeners on parent elements.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;Network&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Network&quot;&gt;Network&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;See all requests.&lt;/strong&gt;&lt;/strong&gt; The Network panel logs every request the page makes. Each row shows method, status, type, size, and timing. Click any request for details.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/network/reference#filter-type&quot;&gt;Filter by type&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; The filter bar has buttons for XHR, JS, CSS, Img, Media, Font, Doc, WS, and more. Click one to show only that type.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/network/reference#throttling&quot;&gt;Throttle network speed&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; The “No throttling” dropdown lets you simulate Slow 3G, Fast 3G, or custom speeds. Useful for testing how your site behaves on bad connections.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Simulate offline.&lt;/strong&gt;&lt;/strong&gt; Check the “Offline” checkbox next to the throttling dropdown. The page can’t make any network requests.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/network/reference#disable-cache&quot;&gt;Disable cache&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; “Disable cache” checkbox at the top of the Network panel. Only active while DevTools is open. Forces fresh downloads of every resource.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Request timing.&lt;/strong&gt;&lt;/strong&gt; Click a request, go to the Timing tab. Shows DNS lookup, TCP connection, TLS negotiation, time to first byte, and content download. The waterfall chart shows all of these visually for every request.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&quot;network-timing.png&quot; alt=&quot;Network request timing breakdown&quot;&gt;
  &lt;figcaption&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/network/reference#timing&quot;&gt;Request timing&lt;/a&gt;. DNS, TCP, TLS, TTFB, and download broken out.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/network/reference#copy&quot;&gt;Copy as cURL&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Right-click any request, Copy &amp;gt; Copy as cURL. Paste it in your terminal to replay the exact same request with all headers and cookies. Copy as fetch does the same for JavaScript.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/network/reference#block&quot;&gt;Block requests&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Right-click a request, “Block request URL” or “Block request domain.” The page will behave as if that resource doesn’t exist. Good for testing graceful degradation.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Replay a request.&lt;/strong&gt;&lt;/strong&gt; Right-click a request, “Replay XHR.” Sends the exact same request again.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/network/reference#frames&quot;&gt;See WebSocket messages&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Click a WebSocket connection in the Network panel, go to the Messages tab. Shows every frame sent and received.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Export HAR.&lt;/strong&gt;&lt;/strong&gt; The download icon exports all network activity as a &lt;a href=&quot;&amp;lt;https://en.wikipedia.org/wiki/HAR_(file_format)&amp;gt;&quot;&gt;HAR file&lt;/a&gt;. You can share it or import it later for analysis.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;Performance&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Performance&quot;&gt;Performance&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Record.&lt;/strong&gt;&lt;/strong&gt; Performance panel, click record, interact with the page, stop recording. You get a flame chart showing exactly what the browser did: script evaluation, layout, paint, composite.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&quot;flame-chart.png&quot; alt=&quot;Performance panel flame chart&quot;&gt;
  &lt;figcaption&gt;The &lt;a href=&quot;https://developer.chrome.com/docs/devtools/performance&quot;&gt;Performance panel&lt;/a&gt; flame chart. Script, layout, paint, and composite all visible.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Find layout thrashing.&lt;/strong&gt;&lt;/strong&gt; Look for purple “Layout” bars in the flame chart. Click one to see the call stack that caused it. Common causes: reading &lt;code&gt;offsetHeight&lt;/code&gt; or &lt;code&gt;getBoundingClientRect&lt;/code&gt; then changing styles in a loop.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Paint flashing.&lt;/strong&gt;&lt;/strong&gt; &lt;code&gt;Cmd + Shift + P&lt;/code&gt;, type “Show Rendering”, check “Paint flashing.” Green highlights appear wherever the browser repaints. Useful for catching unnecessary repaints.&lt;/p&gt;
&lt;figure&gt;
  &lt;img src=&quot;paint-flashing.gif&quot; alt=&quot;Paint flashing in action&quot;&gt;
  &lt;figcaption&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/rendering#paint-flashing&quot;&gt;Paint flashing&lt;/a&gt;. Green highlights wherever the browser repaints.&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Layout shift regions.&lt;/strong&gt;&lt;/strong&gt; In the same Rendering drawer, check “Layout Shift Regions.” Blue highlights show elements that shifted position, which directly causes &lt;a href=&quot;https://web.dev/articles/cls&quot;&gt;CLS (Cumulative Layout Shift)&lt;/a&gt; problems.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/rendering#fps&quot;&gt;FPS meter&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; &lt;code&gt;Cmd + Shift + P&lt;/code&gt;, type “Show FPS.” Gives you a real-time frames-per-second overlay.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Web Vitals.&lt;/strong&gt;&lt;/strong&gt; The Performance panel has a Web Vitals lane that shows LCP, FID, and CLS events during the recording. Or run a Lighthouse audit for a full report.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;CPU throttling.&lt;/strong&gt;&lt;/strong&gt; The Performance panel has a CPU throttle dropdown (4x slowdown, 6x slowdown). Simulates a slower device.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;Hidden-Power-Tools&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Hidden-Power-Tools&quot;&gt;Hidden Power Tools&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/javascript/snippets&quot;&gt;Snippets&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Sources panel &amp;gt; Snippets tab. Write JavaScript, save it, run it with &lt;code&gt;Cmd + Enter&lt;/code&gt;. Snippets persist across sessions. I keep a few for common debugging routines: clearing storage, logging all event listeners, dumping performance marks.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/overrides&quot;&gt;Local overrides&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Sources panel &amp;gt; Overrides tab. Select a local folder, then edit any file in Sources. Your changes save locally and load instead of the server version on refresh. You can patch a production site without deploying.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/workspaces&quot;&gt;Workspaces&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Sources panel &amp;gt; Filesystem tab. Add your project folder and DevTools links files to your local source. CSS changes in the Styles panel save directly to your &lt;code&gt;.css&lt;/code&gt; files. Persistent live editing.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;code&gt;monitor(fn)&lt;/code&gt; and &lt;code&gt;debug(fn)&lt;/code&gt;.&lt;/strong&gt;&lt;/strong&gt; &lt;code&gt;monitor(fn)&lt;/code&gt; logs calls. &lt;code&gt;debug(fn)&lt;/code&gt; sets a breakpoint on the first line of the function. Both only work in the console.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;&lt;a href=&quot;https://developer.chrome.com/docs/devtools/overrides#override-headers&quot;&gt;Override response headers&lt;/a&gt;.&lt;/strong&gt;&lt;/strong&gt; Network panel &amp;gt; right-click a request &amp;gt; “Override headers.” Lets you test how your page reacts to different CORS headers, cache policies, etc. without changing the server.&lt;/p&gt;
&lt;/section&gt;

&lt;hr&gt;
&lt;p&gt;&lt;code&gt;web&lt;/code&gt; &lt;code&gt;tutorial&lt;/code&gt; &lt;code&gt;tool&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.tseeley.com/about/&quot;&gt;Thomas Seeley&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://bsky.app/profile/tseeley.com&quot;&gt;@tseeley.com on Bluesky&lt;/a&gt;, &lt;a href=&quot;https://mastodon.social/@iamseeley&quot;&gt;@iamseeley on Mastodon&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;larr; &lt;a href=&quot;https://www.tseeley.com/posts/we-forked-typescript/&quot;&gt;We forked TypeScript&lt;/a&gt; · &lt;a href=&quot;https://www.tseeley.com/posts/hello-membrane/&quot;&gt;Hello, Membrane&lt;/a&gt; &amp;rarr;&lt;/p&gt;
</content></entry><entry><title>Hello, Membrane</title><id>https://www.tseeley.com/posts/hello-membrane/</id><updated>2024-11-10T00:00:00+00:00</updated><author><name>Thomas Seeley</name></author><link href="https://www.tseeley.com/posts/hello-membrane/" rel="alternate" type="text/html"/><published>2024-11-10T00:00:00+00:00</published><content type="html">
&lt;p&gt;It’s been a busy, exciting past few months. I joined &lt;a href=&quot;http://membrane.io/&quot;&gt;membrane.io&lt;/a&gt; as an intern in September, and I’m having a great time making improvements to the platform and building things in user space.&lt;/p&gt;
&lt;section id=&quot;Whats-Membrane&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Whats-Membrane&quot;&gt;What’s Membrane?&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Membrane is a serverless platform for developing JavaScript/TypeScript programs.&lt;/p&gt;
&lt;p&gt;Every program you create in your Membrane workspace becomes part of your graph, and the programs can connect to each other through this graph.&lt;/p&gt;
&lt;video controls width=&quot;100%&quot; src=&quot;https://docs.membrane.io/videos/add-connections.mp4#t=0.1&quot;&gt;&lt;/video&gt;
&lt;p&gt;There are a few key things that set Membrane apart from other serverless platforms:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Programs have built-in state - no need to set up a database
&lt;/li&gt;
&lt;li&gt;
Everything gets logged before it happens - if it’s not in the logs, it didn’t happen
&lt;/li&gt;
&lt;li&gt;
Each program gets an email address - handle incoming emails by exporting an &lt;code&gt;email&lt;/code&gt; function
&lt;/li&gt;
&lt;li&gt;
Each program gets its own endpoint - handle HTTP requests by exporting an &lt;code&gt;endpoint&lt;/code&gt; function
&lt;/li&gt;
&lt;li&gt;
Programs can use other programs as building blocks through graph connections
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;What-Ive-Been-Working-On&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#What-Ive-Been-Working-On&quot;&gt;What I’ve Been Working On.&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Most of my time has been spent on Membrane’s API drivers. Drivers let you interact with external APIs through Membrane’s graph.&lt;/p&gt;
&lt;p&gt;I’ve been improving existing drivers like &lt;a href=&quot;https://www.membrane.io/share/membrane/discord&quot;&gt;Discord&lt;/a&gt; and &lt;a href=&quot;https://www.membrane.io/share/membrane/anthropic&quot;&gt;Anthropic&lt;/a&gt; and building a &lt;a href=&quot;https://membrane.io/share/iamseeley/driver-generator&quot;&gt;tool&lt;/a&gt; to generate new ones. The more drivers on Membrane, the more useful tools and automations we can build!&lt;/p&gt;
&lt;p&gt;A driver exposes API endpoints as nodes (fields, actions, events) that you can reference in your graph with a simple syntax.&lt;/p&gt;
&lt;p&gt;For example, &lt;code&gt;github:users.one(name:&quot;membrane-io&quot;)&lt;/code&gt; tells Membrane to get a specific GitHub user - but here’s what’s cool: even though that API call returns all of the user’s data, you can selectively reference just the pieces you need in other programs, like if we want to get their avatar: &lt;code&gt;github:users.one(name:&quot;membrane-io&quot;).avatar_url&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;strong&gt;Other Projects and Improvements:&lt;/strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Implemented type inference for Membrane &lt;code&gt;state&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
Dynamic OG images for the changelog, packages, and docs
&lt;/li&gt;
&lt;li&gt;
Made a driver for the Membrane API: &lt;a href=&quot;https://www.membrane.io/share/iamseeley/mem&quot;&gt;mem&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I’m excited to start building more drivers and example tools/automations :).&lt;/p&gt;
&lt;p&gt;If you’d like to learn more about Membrane check these out:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&quot;https://notes.just-be.dev/Membrane%2C+A+Living+Computational+Environment&quot;&gt;Justin Bennett: Membrane, A Living Computational Environment&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://www.devtools.fm/episode/46&quot;&gt;Juan Campa - devtoolsFM episode&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://www.membrane.io/blog/changelog-0.9&quot;&gt;Membrane Changelog&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://docs.membrane.io/getting-started/intro/&quot;&gt;Membrane Docs&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And join the &lt;a href=&quot;https://discord.gg/gBK9xP3z&quot;&gt;Discord&lt;/a&gt;!&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;Want-to-Help-Shape-Membrane&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Want-to-Help-Shape-Membrane&quot;&gt;Want to Help Shape Membrane?&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;We’re looking for developers to try out Membrane and share their feedback!&lt;/p&gt;
&lt;p&gt;If you’re interested in participating in user interviews, reach out to me at &lt;a href=&quot;mailto:thomas@membrane.io&quot;&gt;thomas@membrane.io&lt;/a&gt;. We’d love to hear your thoughts and help you get started building tools for yourself or for your company.&lt;/p&gt;
&lt;aside&gt;Be on the lookout for some updates coming to Membrane...soon you&apos;ll be able to create UIs with the programs on your graph!&lt;/aside&gt;
&lt;/section&gt;

&lt;hr&gt;
&lt;p&gt;&lt;code&gt;membrane&lt;/code&gt; &lt;code&gt;javascript&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.tseeley.com/about/&quot;&gt;Thomas Seeley&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://bsky.app/profile/tseeley.com&quot;&gt;@tseeley.com on Bluesky&lt;/a&gt;, &lt;a href=&quot;https://mastodon.social/@iamseeley&quot;&gt;@iamseeley on Mastodon&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;larr; &lt;a href=&quot;https://www.tseeley.com/posts/how-to-use-chrome-devtools/&quot;&gt;How to Use Chrome DevTools&lt;/a&gt; · &lt;a href=&quot;https://www.tseeley.com/posts/nvim/&quot;&gt;Neovim Cheatsheet&lt;/a&gt; &amp;rarr;&lt;/p&gt;
</content></entry><entry><title>Neovim Cheatsheet</title><id>https://www.tseeley.com/posts/nvim/</id><updated>2024-10-15T00:00:00+00:00</updated><author><name>Thomas Seeley</name></author><link href="https://www.tseeley.com/posts/nvim/" rel="alternate" type="text/html"/><published>2024-10-15T00:00:00+00:00</published><content type="html">
&lt;section id=&quot;Basic-Navigation&quot;&gt;
&lt;h1&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Basic-Navigation&quot;&gt;Basic Navigation&lt;/a&gt;&lt;/h1&gt;
&lt;section id=&quot;Movement&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Movement&quot;&gt;Movement&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;h&lt;/code&gt; &lt;code&gt;j&lt;/code&gt; &lt;code&gt;k&lt;/code&gt; &lt;code&gt;l&lt;/code&gt; - Left, Down, Up, Right
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;w&lt;/code&gt; - Next word start
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;b&lt;/code&gt; - Previous word start
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;e&lt;/code&gt; - End of word
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;0&lt;/code&gt; - Start of line
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;^&lt;/code&gt; - First non-blank character
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;$&lt;/code&gt; - End of line
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;gg&lt;/code&gt; - Start of file
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;G&lt;/code&gt; - End of file
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{number}G&lt;/code&gt; - Go to line number
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;%&lt;/code&gt; - Jump to matching bracket
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;Scrolling&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Scrolling&quot;&gt;Scrolling&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Ctrl-d&lt;/code&gt; - Half page down
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Ctrl-u&lt;/code&gt; - Half page up
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Ctrl-f&lt;/code&gt; - Page down
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Ctrl-b&lt;/code&gt; - Page up
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;zz&lt;/code&gt; - Center cursor on screen
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;Editing&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Editing&quot;&gt;Editing&lt;/a&gt;&lt;/h2&gt;
&lt;section id=&quot;Insert-Mode&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Insert-Mode&quot;&gt;Insert Mode&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;i&lt;/code&gt; - Insert before cursor
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;I&lt;/code&gt; - Insert at start of line
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;a&lt;/code&gt; - Append after cursor
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;A&lt;/code&gt; - Append at end of line
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;o&lt;/code&gt; - Open new line below
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;O&lt;/code&gt; - Open new line above
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Esc&lt;/code&gt; - Exit insert mode
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;Deletion&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Deletion&quot;&gt;Deletion&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;x&lt;/code&gt; - Delete character under cursor
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dd&lt;/code&gt; - Delete &lt;a href=&quot;line&quot;&gt;line&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dw&lt;/code&gt; - Delete word
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;d$&lt;/code&gt; - Delete to end of line
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;d0&lt;/code&gt; - Delete to start of line
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{number}dd&lt;/code&gt; - Delete N lines
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;CopyPaste&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#CopyPaste&quot;&gt;Copy/Paste&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;yy&lt;/code&gt; - Yank (copy) line
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;yw&lt;/code&gt; - Yank word
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;y$&lt;/code&gt; - Yank to end of line
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;p&lt;/code&gt; - Paste after cursor
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;P&lt;/code&gt; - Paste before cursor
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&quot;+y&lt;/code&gt; - Copy to system clipboard
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&quot;+p&lt;/code&gt; - Paste from system clipboard
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;UndoRedo&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#UndoRedo&quot;&gt;Undo/Redo&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;u&lt;/code&gt; - Undo
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Ctrl-r&lt;/code&gt; - Redo
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.&lt;/code&gt; - Repeat last command
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;Visual-Mode&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Visual-Mode&quot;&gt;Visual Mode&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;v&lt;/code&gt; - Character-wise visual
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;V&lt;/code&gt; - Line-wise visual
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Ctrl-v&lt;/code&gt; - Block visual
&lt;/li&gt;
&lt;li&gt;
Select then &lt;code&gt;d&lt;/code&gt; to delete, &lt;code&gt;y&lt;/code&gt; to copy
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;/section&gt;
&lt;section id=&quot;Search-Replace&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Search-Replace&quot;&gt;Search &amp;amp; Replace&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/pattern&lt;/code&gt; - Search forward
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;?pattern&lt;/code&gt; - Search backward
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;n&lt;/code&gt; - Next match
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;N&lt;/code&gt; - Previous match
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;*&lt;/code&gt; - Search word under cursor
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:%s/old/new/g&lt;/code&gt; - Replace all in file
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:%s/old/new/gc&lt;/code&gt; - Replace with confirmation
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;File-Operations&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#File-Operations&quot;&gt;File Operations&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;:w&lt;/code&gt; - Save file
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:wq&lt;/code&gt; or &lt;code&gt;:x&lt;/code&gt; - Save and quit
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:q&lt;/code&gt; - Quit
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:q!&lt;/code&gt; - Quit without saving
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:e filename&lt;/code&gt; - Open file
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:bn&lt;/code&gt; - Next buffer
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:bp&lt;/code&gt; - Previous buffer
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;My-Custom-Keymaps&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#My-Custom-Keymaps&quot;&gt;My Custom Keymaps&lt;/a&gt;&lt;/h2&gt;
&lt;section id=&quot;Leader-Key-Space&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Leader-Key-Space&quot;&gt;Leader Key: &lt;code&gt;&amp;lt;Space&amp;gt;&lt;/code&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;/section&gt;
&lt;section id=&quot;File-Navigation&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#File-Navigation&quot;&gt;File Navigation&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-&lt;/code&gt; - Open oil.nvim file explorer
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Space&amp;gt;ff&lt;/code&gt; - Find files (Telescope)
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Space&amp;gt;fg&lt;/code&gt; - Live grep (search in files)
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Space&amp;gt;fb&lt;/code&gt; - List buffers
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Space&amp;gt;fh&lt;/code&gt; - Help tags
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;Wiki-Navigation&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Wiki-Navigation&quot;&gt;Wiki Navigation&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Space&amp;gt;ni&lt;/code&gt; - Wiki index
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Space&amp;gt;nd&lt;/code&gt; - Today’s daily note
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Space&amp;gt;nD&lt;/code&gt; - Daily notes index
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Space&amp;gt;nw&lt;/code&gt; - Weekly notes
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Space&amp;gt;nm&lt;/code&gt; - Monthly notes
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Space&amp;gt;ny&lt;/code&gt; - Yearly notes
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;VimWiki-Specific&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#VimWiki-Specific&quot;&gt;VimWiki Specific&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Enter&amp;gt;&lt;/code&gt; - Follow/create wiki link
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Backspace&amp;gt;&lt;/code&gt; - Go back
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Tab&amp;gt;&lt;/code&gt; - Next link
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Shift-Tab&amp;gt;&lt;/code&gt; - Previous link
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Ctrl-Space&amp;gt;&lt;/code&gt; - Toggle task checkbox
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;LSP&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#LSP&quot;&gt;LSP&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;K&lt;/code&gt; - Hover documentation
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;gd&lt;/code&gt; - Go to definition
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;gr&lt;/code&gt; - Find references
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Ctrl-Space&amp;gt;&lt;/code&gt; - Trigger completion
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;CR&amp;gt;&lt;/code&gt; - Confirm completion
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;Oilnvim-File-Explorer&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Oilnvim-File-Explorer&quot;&gt;Oil.nvim File Explorer&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-&lt;/code&gt; - Open parent directory
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Enter&amp;gt;&lt;/code&gt; - Open file/directory
&lt;/li&gt;
&lt;li&gt;
Edit text to rename
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dd&lt;/code&gt; - Delete file
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;o&lt;/code&gt; - Create new file
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:w&lt;/code&gt; - Save changes
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;q&lt;/code&gt; - Close oil
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;/section&gt;
&lt;section id=&quot;Window-Management&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Window-Management&quot;&gt;Window Management&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;:split&lt;/code&gt; or &lt;code&gt;:sp&lt;/code&gt; - Horizontal split
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:vsplit&lt;/code&gt; or &lt;code&gt;:vsp&lt;/code&gt; - Vertical split
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Ctrl-w h/j/k/l&lt;/code&gt; - Navigate between windows
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Ctrl-w =&lt;/code&gt; - Equal window sizes
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Ctrl-w q&lt;/code&gt; - Close window
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;Tips-Tricks&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Tips-Tricks&quot;&gt;Tips &amp;amp; Tricks&lt;/a&gt;&lt;/h2&gt;
&lt;section id=&quot;Multiple-Cursors-Visual-Block&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Multiple-Cursors-Visual-Block&quot;&gt;Multiple Cursors (Visual Block)&lt;/a&gt;&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;Ctrl-v&lt;/code&gt; - Start visual block
&lt;/li&gt;
&lt;li&gt;
Select lines with &lt;code&gt;j&lt;/code&gt;/&lt;code&gt;k&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;I&lt;/code&gt; - Insert at start of all lines
&lt;/li&gt;
&lt;li&gt;
Type text, press &lt;code&gt;Esc&lt;/code&gt; twice
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
&lt;section id=&quot;Macros&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Macros&quot;&gt;Macros&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;q{letter}&lt;/code&gt; - Start recording macro
&lt;/li&gt;
&lt;li&gt;
Do actions
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;q&lt;/code&gt; - Stop recording
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@{letter}&lt;/code&gt; - Replay macro
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@@&lt;/code&gt; - Replay last macro
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;Marks&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Marks&quot;&gt;Marks&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;m{letter}&lt;/code&gt; - Set mark
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&apos;{letter}&lt;/code&gt; - Jump to mark
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&apos;&apos;&lt;/code&gt; - Jump back to previous position
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;Command-Line&quot;&gt;
&lt;h3&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Command-Line&quot;&gt;Command Line&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;:!command&lt;/code&gt; - Run shell command
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:r !command&lt;/code&gt; - Insert command output
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:%!command&lt;/code&gt; - Filter file through command
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;/section&gt;
&lt;section id=&quot;VimWiki-Tasks&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#VimWiki-Tasks&quot;&gt;VimWiki Tasks&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;- [ ]&lt;/code&gt; - Create task
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Ctrl-Space&lt;/code&gt; - Toggle task state
- &lt;code&gt;[ ]&lt;/code&gt; - Not done
- &lt;code&gt;[.]&lt;/code&gt; - 0-33% done
- &lt;code&gt;[o]&lt;/code&gt; - 34-66% done
- &lt;code&gt;[O]&lt;/code&gt; - 67-99% done
- &lt;code&gt;[X]&lt;/code&gt; - Done
&lt;/li&gt;
&lt;li&gt;
Nested tasks auto-update parent status
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id=&quot;Resources&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Resources&quot;&gt;Resources&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;:help&lt;/code&gt; - Neovim help
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:help {topic}&lt;/code&gt; - Help on specific topic
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;:Tutor&lt;/code&gt; - Interactive Neovim tutorial
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;/section&gt;

&lt;hr&gt;
&lt;p&gt;&lt;code&gt;cheatsheet&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.tseeley.com/about/&quot;&gt;Thomas Seeley&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://bsky.app/profile/tseeley.com&quot;&gt;@tseeley.com on Bluesky&lt;/a&gt;, &lt;a href=&quot;https://mastodon.social/@iamseeley&quot;&gt;@iamseeley on Mastodon&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;larr; &lt;a href=&quot;https://www.tseeley.com/posts/hello-membrane/&quot;&gt;Hello, Membrane&lt;/a&gt; · &lt;a href=&quot;https://www.tseeley.com/posts/maze-playground/&quot;&gt;Maze Playground&lt;/a&gt; &amp;rarr;&lt;/p&gt;
</content></entry><entry><title>Maze Playground</title><id>https://www.tseeley.com/posts/maze-playground/</id><updated>2024-08-22T00:00:00+00:00</updated><author><name>Thomas Seeley</name></author><link href="https://www.tseeley.com/posts/maze-playground/" rel="alternate" type="text/html"/><published>2024-08-22T00:00:00+00:00</published><content type="html">
&lt;p&gt;I read Andrew Healey’s &lt;a href=&quot;https://healeycodes.com/generating-mazes&quot;&gt;Generating Mazes&lt;/a&gt; and wanted to see the algorithms work. Not just the finished maze, but each step of the generation. Walls getting removed one at a time, the path carving through the grid.&lt;/p&gt;
&lt;p&gt;So I built a &lt;a href=&quot;https://github.com/iamseeley/maze-playground&quot;&gt;small playground&lt;/a&gt; for it. Deno, TypeScript, and a &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;section id=&quot;The-Data-Model&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#The-Data-Model&quot;&gt;The Data Model&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A maze is a grid of cells. Each cell has four walls and knows whether it’s been visited.&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#888888;&quot;&gt;export &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;class Cell implements CellInterface &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;{
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  position&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;Position&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  hasTopWall&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;boolean&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  hasRightWall&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;boolean&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  hasBottomWall&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;boolean&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  hasLeftWall&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;boolean&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  visited&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;boolean&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  removeWall&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;neighbor: CellInterface&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;void {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    const dx = neighbor.position.x - this.position.x;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    const dy = neighbor.position.y - this.position.y;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;if &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(dx === &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;this.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;hasRightWall &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;      neighbor&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;hasLeftWall &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#666666;&quot;&gt;// ... and so on for each direction
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;removeWall&lt;/code&gt; figures out which direction the neighbor is in and removes the wall on both sides. That’s the core operation of maze generation: two cells become connected.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;Generators-for-Stepping&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Generators-for-Stepping&quot;&gt;Generators for Stepping&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The part I liked most was using &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_generators&quot;&gt;JavaScript generators&lt;/a&gt; for the algorithms. DFS yields after each step, which means the UI can consume it at whatever pace it wants.&lt;/p&gt;
&lt;pre data-lang=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#888888;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;generateSteps&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;maze: MazeInterface&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;startCell: CellInterface&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;: Generator&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;lt;{ &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;currentCell&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;CellInterface &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}&amp;gt; {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  const stack&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;CellInterface&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;[] = [&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;startCell&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  startCell.visited = true;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;while &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(stack&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt; &amp;gt; 0&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;currentCell &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;stack&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;stack&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;length &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;- &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;];
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;yield { &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;currentCell &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;};
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;unvisitedNeighbors &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;maze&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;getNeighbors&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;currentCell&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;filter&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(neighbor =&amp;gt; !&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;neighbor&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;visited&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;if (&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;unvisitedNeighbors&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;length &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;) {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;randomIndex &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;floor&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;random&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;() * &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;unvisitedNeighbors&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;const &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;chosenNeighbor &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;unvisitedNeighbors&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;randomIndex&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;];
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;      currentCell&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;removeWall&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;chosenNeighbor&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;      chosenNeighbor&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;visited &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;;
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;      stack&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;chosenNeighbor&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;);
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;} else {
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;      stack&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;();
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The UI runs a &lt;code&gt;setInterval&lt;/code&gt; at 50ms that calls &lt;code&gt;generator.next()&lt;/code&gt;, snapshots the maze state, and renders it. After generation is done, a slider lets you scrub back through every step. You can watch the algorithm think.&lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;Whats-There-Whats-Not&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#Whats-There-Whats-Not&quot;&gt;What’s There, What’s Not&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Right now only &lt;a href=&quot;https://en.wikipedia.org/wiki/Depth-first_search&quot;&gt;DFS&lt;/a&gt; is implemented. The dropdown lists &lt;a href=&quot;https://en.wikipedia.org/wiki/Maze_generation_algorithm#Aldous-Broder_algorithm&quot;&gt;Aldous-Broder&lt;/a&gt;, &lt;a href=&quot;https://en.wikipedia.org/wiki/Maze_generation_algorithm#Randomized_Prim&apos;s_algorithm&quot;&gt;Prim’s&lt;/a&gt;, and &lt;a href=&quot;https://en.wikipedia.org/wiki/Maze_generation_algorithm#Randomized_Kruskal&apos;s_algorithm&quot;&gt;Kruskal’s&lt;/a&gt; but they’re stubs. I’d like to add them eventually because the interesting thing about maze algorithms is how different the mazes &lt;em&gt;feel&lt;/em&gt;. DFS creates long winding corridors with few branches. Aldous-Broder creates more uniform, random-looking mazes. Same grid, different character.&lt;/p&gt;
&lt;p&gt;The rendering is simple Canvas drawing. Visited cells get a gray fill, the current cell gets a blue highlight, and walls are just lines. Nothing fancy, but it’s enough to see what’s happening.&lt;/p&gt;
&lt;/section&gt;

&lt;hr&gt;
&lt;p&gt;&lt;code&gt;typescript&lt;/code&gt; &lt;code&gt;algorithms&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.tseeley.com/about/&quot;&gt;Thomas Seeley&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://bsky.app/profile/tseeley.com&quot;&gt;@tseeley.com on Bluesky&lt;/a&gt;, &lt;a href=&quot;https://mastodon.social/@iamseeley&quot;&gt;@iamseeley on Mastodon&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;larr; &lt;a href=&quot;https://www.tseeley.com/posts/nvim/&quot;&gt;Neovim Cheatsheet&lt;/a&gt; · &lt;a href=&quot;https://www.tseeley.com/posts/schemeing/&quot;&gt;Scheme-ing&lt;/a&gt; &amp;rarr;&lt;/p&gt;
</content></entry><entry><title>Scheme-ing</title><id>https://www.tseeley.com/posts/schemeing/</id><updated>2024-07-04T00:00:00+00:00</updated><author><name>Thomas Seeley</name></author><link href="https://www.tseeley.com/posts/schemeing/" rel="alternate" type="text/html"/><published>2024-07-04T00:00:00+00:00</published><content type="html">
&lt;p&gt;I’ve been reading &lt;a href=&quot;https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/index.html&quot;&gt;SICP&lt;/a&gt; on and off. To be honest, I’ve only made it a few chapters in and I think that’s as far as I’ll go.&lt;/p&gt;
&lt;p&gt;Around the same time I read &lt;a href=&quot;https://bookshop.org/books/wolf-in-white-van/9781250074713&quot;&gt;&lt;em&gt;Wolf in White Van&lt;/em&gt;&lt;/a&gt; by John Darnielle. It’s a novel about a guy who runs a &lt;a href=&quot;https://en.wikipedia.org/wiki/Interactive_fiction&quot;&gt;text-based adventure game&lt;/a&gt; by mail. Players send in their moves, he sends back what happens. The game is called Trace Italian! The whole book is told in reverse, which gives it this strange gravity. You know where the story ends up before you know how it started.&lt;/p&gt;
&lt;p&gt;I thought it would be fun to build a text adventure in Scheme. So I did!&lt;/p&gt;
&lt;section id=&quot;The-Game&quot;&gt;
&lt;h2&gt;&lt;a class=&quot;heading-anchor&quot; href=&quot;#The-Game&quot;&gt;The Game&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;It’s small. Four rooms, directional movement, a game loop. No items, no puzzles, no win condition. Just the skeleton of a world you can walk around in.&lt;/p&gt;
&lt;pre data-lang=&quot;scheme&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;define &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;rooms
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  (&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;list
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;   (&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;list &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;living-room &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;You are in the living room. There is a door to the north and a kitchen to the west.&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;   (&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;list &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;kitchen &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;You are in the kitchen. There is a living room to the east.&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;   (&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;list &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;hallway &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;You are in the hallway. There is a living room to the south and a bedroom to the north.&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;   (&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;list &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;bedroom &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;You are in the bedroom. There is a hallway to the south.&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)))
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Rooms are lists. Connections between rooms are lists. The game state is which room you’re in.&lt;/p&gt;
&lt;pre data-lang=&quot;scheme&quot;&gt;&lt;code&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;define &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;(game-loop)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  (describe-current-room)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;  (&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;let &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;((command (get-command)))
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    (&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;cond &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;((eq&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;? &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;command &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;north) (move &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;north))
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;          ((eq&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;? &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;command &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;south) (move &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;south))
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;          ((eq&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;? &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;command &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;east) (move &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;east))
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;          ((eq&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;? &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;command &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;west) (move &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;west))
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;          ((eq&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;? &lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;command &lt;/span&gt;&lt;span style=&quot;color:#e0c020;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;quit) (display &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;Goodbye!&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;                                (&lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;newline&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;                                (exit))
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;          (else (display &lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-style:italic;color:#e0c020;&quot;&gt;Invalid command.&lt;/span&gt;&lt;span style=&quot;color:#888888;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;                (&lt;/span&gt;&lt;span style=&quot;font-weight:bold;color:#eeeeee;&quot;&gt;newline&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;)))
&lt;/span&gt;&lt;span style=&quot;color:#e2e2e5;&quot;&gt;    (game-loop)))
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The game loop is a recursive function that describes where you are, reads a command, acts on it, then calls itself. No &lt;code&gt;while&lt;/code&gt; loop, no mutable iterator. Just a function that calls itself forever until you quit.&lt;/p&gt;
&lt;p&gt;It’s a good reminder that you don’t need much to make something interactive. Four rooms and a prompt. That’s a world you can walk around in.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;https://github.com/iamseeley/just-scheme-things/blob/main/adventure.scm&quot;&gt;full source&lt;/a&gt; is about 60 lines. There’s also a &lt;a href=&quot;https://github.com/iamseeley/just-scheme-things/blob/main/tic-tac-toe.scm&quot;&gt;tic-tac-toe&lt;/a&gt; in the same repo from the same weekend.&lt;/p&gt;
&lt;/section&gt;

&lt;hr&gt;
&lt;p&gt;&lt;code&gt;scheme&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.tseeley.com/about/&quot;&gt;Thomas Seeley&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://bsky.app/profile/tseeley.com&quot;&gt;@tseeley.com on Bluesky&lt;/a&gt;, &lt;a href=&quot;https://mastodon.social/@iamseeley&quot;&gt;@iamseeley on Mastodon&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;larr; &lt;a href=&quot;https://www.tseeley.com/posts/maze-playground/&quot;&gt;Maze Playground&lt;/a&gt;&lt;/p&gt;
</content></entry></feed>