<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="https://kaleidawave.github.io/">
  <title>Ben&#39;s Engineering Blog</title>
  <subtitle>writings on the things</subtitle>
  <link href="https://kaleidawave.github.io/feed.xml" rel="self"/>
  <link href="https://kaleidawave.github.io/"/>
  <updated>2026-01-28T00:00:00Z</updated>
  <id>https://kaleidawave.github.io/</id>
  <author>
    <name>Ben</name>
    <email>kaleidawave@gmail.com</email>
  </author>
  <entry>
    <title>A JSON parser in less than 250 lines-of-code</title>
    <link href="https://kaleidawave.github.io/posts/building-a-json-parser/"/>
    <updated>2026-01-28T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/building-a-json-parser/</id>
    <summary>On JSON and how to build a parser for it</summary>
    <content xml:lang="en" type="html">&lt;p&gt;Over the winter break I spent some time working on &lt;a href=&quot;https://github.com/kaleidawave/simple-json-parser&quot;&gt;my JSON parser&lt;/a&gt; I wrote in late 2023. I had seen that with additions I made over the year, it had become a little bloated and had gone above an initially recorded statistic for line-of-code.&lt;/p&gt;
&lt;p&gt;With some simplification to the existing logic I managed to get it to around 250 lines-of-code of Rust counted from the &lt;code&gt;fn&lt;/code&gt; keyword to the last &lt;code&gt;}&lt;/code&gt; brace of the main parsing function.&lt;/p&gt;
&lt;p&gt;This is a quick post outlining some of the tricks and choices made when building this JSON parser.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The library is open-source and on &lt;a href=&quot;https://crates.io/crates/simple-json-parser&quot;&gt;crates.io&lt;/a&gt; but the latest code is under &lt;a href=&quot;https://github.com/kaleidawave/simple-json-parser/pull/6&quot;&gt;this PR&lt;/a&gt; and yet to merge at the time of writing.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;With such a short implementation, I can paste it in its full glory and explain it later!&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Some definitions elided, &lt;a href=&quot;https://github.com/kaleidawave/simple-json-parser/blob/47f7c3304020ebac8de8ca897d4b5fc6ee95f828/lib.rs&quot;&gt;full code here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_with_options&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    options&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ParseOptions&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; cb&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;impl&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;FnMut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;], &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Result&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;), &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONParseError&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find_non_escaped_quoted&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;match_indices&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&amp;quot;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find_map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(idx, _)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; rev &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on[&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;idx]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;bytes&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; last &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; rev&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;take_while&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;chr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;u8&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;chr &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            (last &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;then_some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(idx)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_comment&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(rest) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;strip_prefix&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;#&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; offset &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; rest&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&#92;n&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;unwrap_or&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(rest&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;len&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;on[&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;offset], offset &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(rest) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;strip_prefix&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;//&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; offset &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; rest&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&#92;n&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;unwrap_or&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(rest&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;len&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;on[&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;offset], offset &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(rest) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;strip_prefix&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;/*&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; offset &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; rest&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;*/&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;rest[&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;offset], offset &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;None&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; idx, &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; key_chain, &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; in_object)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Vec&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;_&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&amp;gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Default&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (bytes, tls) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;as_bytes&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(), options&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;top_level_separator);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; tls&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        key_chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;macro_rules!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;emit&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;expr) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;            // TODO pass idx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; res &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;cb&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;key_chain, &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;item);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; res&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;((idx, res));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;macro_rules!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;return_err&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;reason&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;ident) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Err&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONParseError&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                at&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; idx,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                reason&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONParseErrorReason&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::$&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;reason,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;macro_rules!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;skip_whitespace_find_comments&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        () &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;while&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(byte) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(idx) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&#92;t&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&#92;r&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&#92;n&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; byte {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;/&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;#&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; byte {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;((comment, offset)) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_comment&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;on[idx&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;InvalidComment&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; offset;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; options&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;yield_comments {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Comment&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(comment));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;skip_whitespace_find_comments!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;while&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;len&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; in_object {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;skip_whitespace_find_comments!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;&amp;quot;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(idx) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; rest &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;on[&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;][idx&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(offset) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find_non_escaped_quoted&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(rest) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpectedQuote&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                key_chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Slice&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;rest[&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;offset]));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; offset &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;skip_whitespace_find_comments!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;as_bytes&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(idx)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;copied&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;unwrap_or_default&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;:&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;                    // TODO partial could find next &amp;#39;:&amp;#39;?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpectedColon&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpectedKey&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;skip_whitespace_find_comments!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(idx)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;copied&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;{&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;                // little hack&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;skip_whitespace_find_comments!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;}&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(idx) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;EmptyObject&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    in_object &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;continue&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;[&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                key_chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                in_object &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;continue&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;]&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; key_chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;EmptyArray&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(_)) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; options&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;allow_trailing_commas &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    _ &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpectedEndOfValue&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                in_object &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(key_chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;last&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Slice&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(_)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;&amp;quot;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; rest &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;on[idx&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(offset) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find_non_escaped_quoted&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(rest) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpectedEndOfValue&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; offset &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;JSONString&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;rest[&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;offset])));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;0&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;9&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;-&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;                /// can include bad values&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find_non_number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(chr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(chr, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;0&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;9&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;.&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;e&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;E&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;+&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;-&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; rest &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;on[idx&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(offset) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; rest&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(find_non_number) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpectedEndOfValue&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; offset;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;JSONNumber&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;rest[&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;offset])));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;t&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on[idx&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;starts_with&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Boolean&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;f&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on[idx&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;starts_with&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;false&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Boolean&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;n&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on[idx&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;starts_with&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;null&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Null&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(b &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;}&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; options&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;partial_syntax &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Empty&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; in_object {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; _ &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; key_chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;continue&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            _ &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpectedValue&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;while&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(byte) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(idx) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; key_chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_empty&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;((idx, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; tls&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_some_and&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on[idx&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;starts_with&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(c)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;ref&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; idx)] &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; key_chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;as_mut_slice&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&#92;t&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&#92;r&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&#92;n&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; byte {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;/&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;#&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; byte {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;((comment, offset)) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_comment&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;on[idx&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;InvalidComment&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; offset;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; options&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;yield_comments {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Comment&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(comment));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; new_byte &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;byte &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;ref&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; idx)) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; key_chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;last_mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        key_chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;options&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;allow_trailing_commas {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;skip_whitespace_find_comments!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(b &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;}&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;]&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(idx) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;byte&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; new_byte {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;}&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;byte &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; in_object &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;]&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(key_chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;last&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(_))) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    _ &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpectedEndOfValue&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                key_chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                in_object &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(key_chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;last&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Slice&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(_)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; tl &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; tls&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_some_and&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;_&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(key_chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;as_slice&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(_)]));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(key_chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_empty&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; tl) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpectedBracket&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;((on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;len&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_with_options&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    options&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ParseOptions&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; cb&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;impl&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;FnMut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;], &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Result&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;), &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONParseError&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find_non_escaped_quoted&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;match_indices&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&amp;quot;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find_map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(idx, _)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; rev &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on[&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;idx]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;bytes&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; last &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; rev&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;take_while&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;chr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;u8&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;chr &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            (last &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;then_some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(idx)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_comment&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(rest) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;strip_prefix&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;#&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; offset &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; rest&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&#92;n&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;unwrap_or&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(rest&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;len&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;on[&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;offset], offset &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(rest) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;strip_prefix&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;//&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; offset &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; rest&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&#92;n&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;unwrap_or&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(rest&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;len&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;on[&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;offset], offset &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(rest) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;strip_prefix&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;/*&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; offset &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; rest&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;*/&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;rest[&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;offset], offset &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;None&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; idx, &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; key_chain, &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; in_object)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Vec&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;_&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&amp;gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Default&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (bytes, tls) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;as_bytes&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(), options&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;top_level_separator);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; tls&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        key_chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;macro_rules!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;emit&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;expr) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;            // TODO pass idx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; res &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;cb&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;key_chain, &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;item);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; res&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;((idx, res));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;macro_rules!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;return_err&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;reason&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;ident) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Err&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONParseError&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                at&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; idx,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                reason&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONParseErrorReason&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::$&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;reason,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;macro_rules!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;skip_whitespace_find_comments&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        () &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;while&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(byte) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(idx) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&#92;t&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&#92;r&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&#92;n&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; byte {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;/&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;#&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; byte {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;((comment, offset)) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_comment&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;on[idx&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;InvalidComment&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; offset;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; options&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;yield_comments {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Comment&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(comment));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;skip_whitespace_find_comments!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;while&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;len&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; in_object {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;skip_whitespace_find_comments!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;&amp;quot;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(idx) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; rest &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;on[&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;][idx&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(offset) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find_non_escaped_quoted&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(rest) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpectedQuote&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                key_chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Slice&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;rest[&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;offset]));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; offset &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;skip_whitespace_find_comments!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;as_bytes&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(idx)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;copied&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;unwrap_or_default&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;:&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;                    // TODO partial could find next &amp;#39;:&amp;#39;?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpectedColon&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpectedKey&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;skip_whitespace_find_comments!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(idx)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;copied&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;{&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;                // little hack&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;skip_whitespace_find_comments!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;}&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(idx) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;EmptyObject&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    in_object &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;continue&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;[&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                key_chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                in_object &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;continue&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;]&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; key_chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;EmptyArray&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(_)) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; options&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;allow_trailing_commas &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    _ &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpectedEndOfValue&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                in_object &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(key_chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;last&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Slice&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(_)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;&amp;quot;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; rest &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;on[idx&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;][&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(offset) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find_non_escaped_quoted&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(rest) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpectedEndOfValue&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; offset &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;JSONString&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;rest[&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;offset])));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;0&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;9&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;-&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;                /// can include bad values&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find_non_number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(chr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(chr, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;0&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;9&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;.&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;e&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;E&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;+&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;-&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; rest &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;on[idx&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(offset) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; rest&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(find_non_number) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpectedEndOfValue&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; offset;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;JSONNumber&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;rest[&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;offset])));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;t&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on[idx&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;starts_with&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Boolean&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;f&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on[idx&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;starts_with&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;false&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Boolean&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;n&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on[idx&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;starts_with&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;null&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Null&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(b &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;}&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; options&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;partial_syntax &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Empty&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; in_object {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; _ &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; key_chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;continue&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            _ &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpectedValue&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;while&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(byte) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(idx) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; key_chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_empty&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;((idx, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; tls&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_some_and&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on[idx&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;starts_with&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(c)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;ref&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; idx)] &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; key_chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;as_mut_slice&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&#92;t&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&#92;r&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&#92;n&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; byte {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;/&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;#&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; byte {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;((comment, offset)) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_comment&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;on[idx&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;InvalidComment&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; offset;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; options&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;yield_comments {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Comment&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(comment));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; new_byte &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;byte &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;ref&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; idx)) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; key_chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;last_mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        key_chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;options&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;allow_trailing_commas {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;skip_whitespace_find_comments!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(b &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;}&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;]&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; bytes&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(idx) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;break&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;byte&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; new_byte {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;}&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;byte &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; in_object &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;]&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(key_chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;last&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(_))) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    _ &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpectedEndOfValue&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                key_chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;pop&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                in_object &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(key_chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;last&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Slice&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(_)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; tl &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; tls&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_some_and&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;_&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(key_chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;as_slice&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Index&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(_)]));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(key_chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_empty&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; tl) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpectedBracket&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;((on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;len&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;p&gt;Some basics of the architecture&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Callback function based (explained later)&lt;/li&gt;
&lt;li&gt;No string copy (values have data based on points into the input buffer)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://crates.io/crates/simple-json-parser/0.0.5/dependencies&quot;&gt;No dependencies&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It supports many features&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/simple-json-parser/blob/improvements/specification.md#new-line-separated&quot;&gt;New line delimited JSON&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/simple-json-parser/blob/improvements/specification.md#trailing-commas-1&quot;&gt;Trailing commas&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/simple-json-parser/blob/improvements/specification.md#comments&quot;&gt;Comments (of many varieties)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/simple-json-parser/blob/improvements/specification.md#extra-characters&quot;&gt;Returning at the end of a value (object, etc.)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/simple-json-parser/blob/improvements/specification.md#early-return&quot;&gt;Early return when a value has been found&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/simple-json-parser/blob/improvements/specification.md#partial-syntax&quot;&gt;Partial source, which is useful when the source is still being worked on&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These are all described in the &lt;a href=&quot;https://github.com/kaleidawave/simple-json-parser/blob/improvements/specification.md&quot;&gt;specification&lt;/a&gt; and are tested with &lt;a href=&quot;https://github.com/kaleidawave/spectra&quot;&gt;spectra&lt;/a&gt; (a tool which allows checking pairwise code blocks representing an input and an output match the process of a program).&lt;/p&gt;
&lt;h3 id=&quot;usage&quot; tabindex=&quot;-1&quot;&gt;Usage&lt;/h3&gt;
&lt;p&gt;The foundations are defining a &lt;em&gt;stack&lt;/em&gt; for the keys &lt;code&gt;key_chain&lt;/code&gt;, when we find a value we run the call the &lt;code&gt;cb&lt;/code&gt; with a reference to the &lt;code&gt;key_chain&lt;/code&gt; and an enum variant instance with the value. For example, for finding values under the path &lt;code&gt;[&amp;quot;message&amp;quot;][&amp;quot;message&amp;quot;]&lt;/code&gt; or &lt;code&gt;[&amp;quot;message&amp;quot;][&amp;quot;level&amp;quot;]&lt;/code&gt; we can use pattern matching in the callback function.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;simple_json_parser&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, parse_with_options &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; parse_json,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; _ &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_json&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;()&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;out, &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Default&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;keys, value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Slice&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;message&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Slice&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(kind &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;message&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;level&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	] &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; keys&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(value) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;println!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;{kind}: {value}&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;None&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;});&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;simple_json_parser&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, parse_with_options &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; parse_json,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; _ &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_json&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;()&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;out, &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Default&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;keys, value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Slice&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;message&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;JSONKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Slice&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(kind &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;message&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;level&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	] &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; keys&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(value) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;println!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;{kind}: {value}&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;None&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;});&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This approaches avoids the need for a &lt;code&gt;HashMap&lt;/code&gt; and allocating entries for values if we do not use them in the program.&lt;/p&gt;
&lt;h3 id=&quot;where-json-crops-up&quot; tabindex=&quot;-1&quot;&gt;Where JSON crops up&lt;/h3&gt;
&lt;p&gt;JSON comes up in written form as&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;package.json&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And in &lt;em&gt;data&lt;/em&gt; form&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;GitHub API&lt;/li&gt;
&lt;li&gt;Cargo output&lt;/li&gt;
&lt;li&gt;(spectra, depict)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;delimited-json&quot; tabindex=&quot;-1&quot;&gt;Delimited JSON&lt;/h3&gt;
&lt;p&gt;The parser &lt;em&gt;supports&lt;/em&gt; new-line-delimited JSON.&lt;/p&gt;
&lt;p&gt;Unfortunately, this is not as simple as running the parser on each item of &lt;a href=&quot;https://doc.rust-lang.org/stable/std/io/struct.Lines.html&quot;&gt;&lt;code&gt;std::io::Lines&lt;/code&gt;&lt;/a&gt; because new-line-delimited JSON can be across multiple lines.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{ &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{ &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;quot;y&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;quot;y2&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{ &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;quot;z&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{ &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{ &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;quot;y&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;quot;y2&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{ &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;quot;z&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;building-parsers&quot; tabindex=&quot;-1&quot;&gt;Building parsers&lt;/h3&gt;
&lt;p&gt;I am building a number of parsers at the moment, my goals with them are&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Configurable: support as much syntax as possible. Use options at runtime to enable &lt;em&gt;additional features&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Lightweight&lt;/li&gt;
&lt;li&gt;Low line of code count&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;gotchas-of-the-approach&quot; tabindex=&quot;-1&quot;&gt;Gotchas of the approach&lt;/h3&gt;
&lt;p&gt;The callback is needed (over a for-loop) because the &lt;code&gt;Iterator&lt;/code&gt; trait is not designed to yield elements that based on the mutable lifetime given in &lt;code&gt;Iterator::next&lt;/code&gt;. We could make it &lt;code&gt;Iterator&lt;/code&gt; iterator but it would have to yield the owned &lt;code&gt;Vec&amp;lt;JSONKey&amp;lt;&#39;_&amp;gt;&amp;gt;&lt;/code&gt;, which would have allocate on each value (rather than use a single allocation). This is a limitation of the trait not &lt;em&gt;for-loops&lt;/em&gt;. We could define a new trait &lt;code&gt;IteratorWithLifetime&lt;/code&gt; which would have &lt;code&gt;find&lt;/code&gt; but not &lt;code&gt;collect&lt;/code&gt; etc. but still would not be usable in classic &lt;em&gt;for-loops&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id=&quot;gotchas-of-parsing-json&quot; tabindex=&quot;-1&quot;&gt;Gotchas of parsing JSON&lt;/h3&gt;
&lt;p&gt;This key-chain contextual parser has to also account for the fact that empty array values &lt;code&gt;[]&lt;/code&gt; and empty object &lt;code&gt;{}&lt;/code&gt; values have some meaning. Thus, we have &lt;code&gt;emit!(RootJSONValue::EmptyObject);&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The parser currently uses a few macros, while normally I do not use them, because of control flow with the early returning it seemed acceptable to use them here. Maybe one day we can have &lt;a href=&quot;https://github.com/kaleidawave/experiments/pull/35&quot;&gt;reverse &lt;code&gt;?&lt;/code&gt; operations&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The parser has cut some small parts of correctness corners for the sake of remaining lightweight.&lt;/p&gt;
&lt;p&gt;It does not check numbers. Again if you are &lt;a href=&quot;https://github.com/kaleidawave/release-downloader/blob/improvements/release-downloader/lib.rs&quot;&gt;trying to get a value from a JSON source&lt;/a&gt; as fast as possible, then there is little need to 1. Check the sequence of characters is valid 2. Parse it into a floating-point number.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find_non_number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(chr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(chr, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;0&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;9&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;.&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;e&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;E&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;+&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;-&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; rest &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;on[idx&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(offset) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; rest&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(find_non_number) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpectedEndOfValue&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;idx &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; offset;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;JSONNumber&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;rest[&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;offset])));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find_non_number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(chr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(chr, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;0&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;9&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;.&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;e&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;E&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;+&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;-&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; rest &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;on[idx&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(offset) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; rest&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(find_non_number) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;return_err!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpectedEndOfValue&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;idx &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; offset;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;emit!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RootJSONValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;JSONNumber&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;rest[&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;offset])));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Instead, we delegate parsing until usage time using the &lt;a href=&quot;https://github.com/kaleidawave/simple-json-parser/blob/47f7c3304020ebac8de8ca897d4b5fc6ee95f828/lib.rs#L55&quot;&gt;&lt;code&gt;value_unwrap&lt;/code&gt;&lt;/a&gt; method on &lt;code&gt;JSONNumber&lt;/code&gt;. We have &lt;a href=&quot;https://github.com/kaleidawave/simple-json-parser/blob/47f7c3304020ebac8de8ca897d4b5fc6ee95f828/lib.rs#L25&quot;&gt;the same for &lt;code&gt;JSONString&lt;/code&gt;&lt;/a&gt; for the required &lt;code&gt;unescape_string_content&lt;/code&gt; transform.&lt;/p&gt;
&lt;p&gt;The parser also does not check for control characters in strings. I am not sure why this restriction is in the JSON specification? Maybe for a reason unrelated to JSON.&lt;/p&gt;
&lt;h3 id=&quot;more-on-performance&quot; tabindex=&quot;-1&quot;&gt;More on performance&lt;/h3&gt;
&lt;p&gt;A pivotal function used in JSON parsing is finding the end of a string. A simple method to achieve this would be&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find_non_escaped_quoted&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&amp;quot;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find_non_escaped_quoted&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&amp;quot;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Unfortunately, the method for including double quotes in strings is not &lt;code&gt;&#92;q&lt;/code&gt;, but instead &lt;code&gt;&#92;&amp;quot;&lt;/code&gt;. This means we have to check whether the last character was escaped. A naïve approach that accounts for this would be the following&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find_non_escaped_quoted&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; characters &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;bytes&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;enumerate&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;while&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;((idx, chr)) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; characters&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;next&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; chr {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; _ &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; characters&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;next&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		} &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;&amp;quot;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; chr {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(idx);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;None&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find_non_escaped_quoted&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; characters &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;bytes&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;enumerate&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;while&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;((idx, chr)) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; characters&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;next&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; chr {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; _ &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; characters&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;next&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		} &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;&amp;quot;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; chr {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(idx);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;None&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But examining for the fact that &lt;code&gt;a&#92;&#92;&amp;quot;&lt;/code&gt;, &lt;code&gt;a&#92;&#92;&#92;&#92;&amp;quot;&lt;/code&gt; and &lt;code&gt;a&#92;&#92;&#92;&#92;&#92;&#92;&amp;quot;&lt;/code&gt; are all ends of a string but &lt;code&gt;a&#92;&amp;quot;&lt;/code&gt;, &lt;code&gt;a&#92;&#92;&#92;&amp;quot;&lt;/code&gt; and &lt;code&gt;a&#92;&#92;&#92;&#92;&#92;&amp;quot;&lt;/code&gt; are not we can instead write the function as&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find_non_escaped_quoted&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;match_indices&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&amp;quot;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find_map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(idx, _)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; rev &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on[&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;idx]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;bytes&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; last &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; rev&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;take_while&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;chr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;u8&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;chr &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		(last &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;then_some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(idx)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find_non_escaped_quoted&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;match_indices&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&amp;quot;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find_map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(idx, _)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; rev &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on[&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;idx]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;bytes&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; last &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; rev&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;take_while&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;chr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;u8&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;chr &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&#92;&#92;&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		(last &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;then_some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(idx)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This &lt;code&gt;find_non_escaped_quoted&lt;/code&gt; function seems to be the bottleneck of the parsing implementation (when compared to other parts such as whitespace skipping etc.). Using &lt;a href=&quot;https://github.com/kaleidawave/depict&quot;&gt;depict&lt;/a&gt; we can compare the number of instructions run for each approach.&lt;/p&gt;
&lt;p&gt;In first (with respect to the least instructions run) is the incorrect but future we would have had &lt;code&gt;&#92;q&lt;/code&gt; if un-escaped to &lt;code&gt;&amp;quot;&lt;/code&gt; function.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;symbol name&lt;/th&gt;
&lt;th&gt;count&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;total&lt;/td&gt;
&lt;td&gt;55834&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;simple_json_parser::parse_with_options&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;21173&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;core::str::pattern::CharSearcher as core::str::pattern::Searcher&amp;gt;::next_match&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;9184&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;simple_json_parser::parse_with_options::find_non_escaped_quoted&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;3584&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;parse::main&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;142&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;std::env::Args as core::iter::traits::iterator::Iterator&amp;gt;::next&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;78&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;main&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The even check approach comes in second&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;symbol name&lt;/th&gt;
&lt;th&gt;count&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;total&lt;/td&gt;
&lt;td&gt;61142&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;simple_json_parser::parse_with_options&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;21173&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;core::str::pattern::CharSearcher as core::str::pattern::Searcher&amp;gt;::next_match&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;9184&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;simple_json_parser::parse_with_options::find_non_escaped_quoted&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;8940&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;parse::main&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;141&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;std::env::Args as core::iter::traits::iterator::Iterator&amp;gt;::next&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;78&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;main&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;With the naïve approach having executed six and half more &lt;strong&gt;AArch64&lt;/strong&gt; operations to find the end of the strings in my &lt;code&gt;5955&lt;/code&gt; byte JSON example&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;symbol name&lt;/th&gt;
&lt;th&gt;count&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;total&lt;/td&gt;
&lt;td&gt;84201&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;simple_json_parser::parse_with_options::find_non_escaped_quoted&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;58528&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;simple_json_parser::parse_with_options&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;21188&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;parse::main&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;146&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;std::env::Args as core::iter::traits::iterator::Iterator&amp;gt;::next&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;78&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;main&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4 id=&quot;comparing-with-a-full-javascript-parser-(ezno)&quot; tabindex=&quot;-1&quot;&gt;Comparing with a full JavaScript parser (Ezno)&lt;/h4&gt;
&lt;p&gt;As JSON is a subset of JavaScript objects, we can run the parser on the source. Here we see that the JSON uses 10x less instructions (&lt;code&gt;55834&lt;/code&gt; vs &lt;code&gt;664 254&lt;/code&gt;) that the full JavaScript parser (so ideally works out as 10x faster).&lt;/p&gt;
&lt;p&gt;Obviously the JavaScript parser is doing more: actually parsing bytes in strings, allocating the parsed in vectors as an abstract syntax tree, storing source positions etc. But it is interesting to see the difference in a lightweight non-recursive parser vs a full JavaScript parser.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;symbol name&lt;/th&gt;
&lt;th&gt;count&lt;/th&gt;
&lt;th&gt;mem_read&lt;/th&gt;
&lt;th&gt;mem_write&lt;/th&gt;
&lt;th&gt;stack_read&lt;/th&gt;
&lt;th&gt;stack_write&lt;/th&gt;
&lt;th&gt;call&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Total&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;664254&lt;/td&gt;
&lt;td&gt;75258&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;6466&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ezno_parser::strings::parse_string&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;108472&lt;/td&gt;
&lt;td&gt;9552&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;225&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ezno_parser::lexer::Lexer::skip&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;56382&lt;/td&gt;
&lt;td&gt;20022&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;ezno_parser::expressions::object_literal::ObjectLiteralMember as ezno_parser::ASTNode&amp;gt;::from_reader&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;32428&lt;/td&gt;
&lt;td&gt;8174&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1072&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ezno_parser::lexer::Lexer::skip_including_comments&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;27404&lt;/td&gt;
&lt;td&gt;6851&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ezno_parser::expressions::Expression::from_reader_after_first_expression&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;16863&lt;/td&gt;
&lt;td&gt;3773&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;140&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;ezno_parser::expressions::object_literal::ObjectLiteral as ezno_parser::ASTNode&amp;gt;::from_reader&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;10727&lt;/td&gt;
&lt;td&gt;4284&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;443&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ezno_parser::lexer::Lexer::is_immediate_keyword_advance&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;9837&lt;/td&gt;
&lt;td&gt;2526&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;309&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ezno_parser::expressions::Expression::from_reader_with_precedence&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;9486&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;556&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ezno_parser::functions::MethodHeader::from_reader&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;9380&lt;/td&gt;
&lt;td&gt;1742&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1072&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;ezno_parser::property_key::PropertyKey&amp;lt;U&amp;gt; as ezno_parser::ASTNode&amp;gt;::from_reader&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;8910&lt;/td&gt;
&lt;td&gt;2160&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;540&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;ezno_parser::comments::WithComment&amp;lt;T&amp;gt; as ezno_parser::ASTNode&amp;gt;::from_reader&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;8335&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;core::slice::memchr::memchr_aligned&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;8234&lt;/td&gt;
&lt;td&gt;754&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ezno_parser::lexer::Lexer::parse_string_literal&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;6525&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;225&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ezno_parser::lexer::Lexer::expect&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;6380&lt;/td&gt;
&lt;td&gt;1450&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;145&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;alloc::borrow::Cow&amp;lt;str&amp;gt; as core::ops::arith::AddAssign&amp;lt;&amp;amp;str&amp;gt;&amp;gt;::add_assign&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;5850&lt;/td&gt;
&lt;td&gt;1575&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ezno_parser::lexer::Lexer::is_immediate_keyword&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;4414&lt;/td&gt;
&lt;td&gt;1104&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;158&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;core::ptr::drop_in_place&amp;lt;ezno_parser::expressions::Expression&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;4296&lt;/td&gt;
&lt;td&gt;1040&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;140&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ezno_parser::lexer::Lexer::is_keyword_advance&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;4154&lt;/td&gt;
&lt;td&gt;938&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;268&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ezno_parser::lexer::Lexer::is_operator_advance&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;3908&lt;/td&gt;
&lt;td&gt;809&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;269&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;core::ptr::drop_in_place&amp;lt; ezno_parser::expressions::object_literal::ObjectLiteralMember &amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2948&lt;/td&gt;
&lt;td&gt;670&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;core::str::converts::from_utf8&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2791&lt;/td&gt;
&lt;td&gt;393&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;T as alloc::slice::&amp;lt;impl [T]&amp;gt;::to_vec_in::ConvertVec&amp;gt;::to_vec&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2592&lt;/td&gt;
&lt;td&gt;360&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;266&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;core::ptr::drop_in_place&amp;lt; ezno_parser::comments::WithComment&amp;lt;ezno_parser::property_key::PropertyKey&amp;lt; ezno_parser::property_key::AlwaysPublic&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2412&lt;/td&gt;
&lt;td&gt;670&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;__rustc::__rdl_alloc&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1785&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ezno_parser::numbers::parse_no_specifier&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1551&lt;/td&gt;
&lt;td&gt;246&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;ezno_parser::expressions::Expression as get_field_by_type::GetFieldByType&amp;lt;source_map::span::BaseSpan&amp;lt;()&amp;gt;&amp;gt;&amp;gt;::get&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1072&lt;/td&gt;
&lt;td&gt;268&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ezno_parser::lexer::Lexer::starts_with_function_header&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1040&lt;/td&gt;
&lt;td&gt;52&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;130&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;blockquote&gt;
&lt;p&gt;This sort of side project work is not only useful for utilities, but simplifying the problem has recently helped to make Ezno faster through realising better ways to write it with prefix match style pattern and paying attention to where &lt;code&gt;skip&lt;/code&gt; calls are made. (more details in the future).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;future&quot; tabindex=&quot;-1&quot;&gt;Future&lt;/h3&gt;
&lt;p&gt;There is still some more things that could be improved in the future. SIMD may be useful in some places. The &lt;code&gt;cb&lt;/code&gt; could yield a mutable reference to &lt;code&gt;idx&lt;/code&gt; that could be used to skip over objects (with something of the form &lt;code&gt;find_next_open_brace&lt;/code&gt;). Once that and a few more things are consolidated then &lt;a href=&quot;https://github.com/kaleidawave/simple-json-parser/pull/6&quot;&gt;the PR&lt;/a&gt; can be merged and these updates can be available to the crate on &lt;code&gt;crates.io&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Any suggestions or feedback is welcome in the comments below!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Ideas on type inference</title>
    <link href="https://kaleidawave.github.io/posts/ideas-on-inference/"/>
    <updated>2025-09-26T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/ideas-on-inference/</id>
    <summary>TypeScript sans annotations</summary>
    <content xml:lang="en" type="html">&lt;p&gt;In the third and final post of Ezno week, we will take a look at two kinds of type inference. One kind what I refer to as &lt;code&gt;forward&lt;/code&gt; and the other as &lt;code&gt;backward&lt;/code&gt;. One &lt;em&gt;implemented&lt;/em&gt; and the other a &lt;em&gt;work-in-progress&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;The word inference in a type-checker commonly refers to creating (or finding) a type &lt;strong&gt;for a parameter&lt;/strong&gt; (or variable in some cases). Often because the annotation is elided (jargon for &lt;em&gt;omitted/missing&lt;/em&gt;). The inference process is a subset the general state of &lt;em&gt;type synthesis&lt;/em&gt;, generating types from syntax.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//                         ↓ no type annotation here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;].&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; item)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//                          	 ↑ refences to `item` resolves to type `number` here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//                         ↓ no type annotation here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;].&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; item)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//                          	 ↑ refences to `item` resolves to type `number` here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;forward-inference%3A-pushing-a-type-forwards&quot; tabindex=&quot;-1&quot;&gt;Forward inference: pushing a type forwards&lt;/h3&gt;
&lt;p&gt;The first kind that I refer to forward is in partially annotated (or realised) source text. We have a function parameter &lt;strong&gt;without an annotation&lt;/strong&gt; but we can figure &lt;em&gt;a type&lt;/em&gt; out through looking at the context of where the containing function is written in.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If you have read &lt;a href=&quot;https://kaleidawave.github.io/posts/specification-speed-schedule&quot;&gt;the section on performance in the last post&lt;/a&gt;, you may have seen that TSC records a time for a &lt;code&gt;bind&lt;/code&gt; pass but Ezno does not. I am not hiding that result, but infact the bind phase and check phase are merged in Ezno. Excluding the pass on top level declarations in a block used for &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Glossary/Hoisting&quot;&gt;hoisting&lt;/a&gt;, the AST is only walked once (compared to twice in TSC &lt;em&gt;I think&lt;/em&gt;).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This can happen with and without annotations. If we declare a function as the value of variable &lt;strong&gt;that is annotated&lt;/strong&gt; we need to &lt;em&gt;push&lt;/em&gt; the annotation forward&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//                                        ↓ no annotation here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;increment&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//                      ↘----------------↗&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//         we push the `number` parameter annotation forward&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//                                        ↓ no annotation here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;increment&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//                      ↘----------------↗&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//         we push the `number` parameter annotation forward&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But we also have cases where the user source is not annotated. For example in &lt;code&gt;Promise.prototype.then&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//                           ↓ no annotation here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;...&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;then&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;res&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//  using information about  ↓&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//  what `fetch` returns     ↓&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//  we can figure out that `res` is a `Response`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//                           ↓ no annotation here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;...&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;then&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;res&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//  using information about  ↓&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//  what `fetch` returns     ↓&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//  we can figure out that `res` is a `Response`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is why I refer to it as &lt;em&gt;forward&lt;/em&gt;. Using an annotation or other context we pass information forward in the source / buffer to figure out the &lt;em&gt;type&lt;/em&gt; of the parameter.&lt;/p&gt;
&lt;h4 id=&quot;the-basics-of-the-implementation&quot; tabindex=&quot;-1&quot;&gt;The basics of the implementation&lt;/h4&gt;
&lt;p&gt;The implementation is quite simple, we pass an &lt;em&gt;expected type&lt;/em&gt; through our &lt;code&gt;synthesise_expression&lt;/code&gt; function.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;synthesise_expression&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	expression&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ezno_parser&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ast&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Expression&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;	// ↓&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	expected_type&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;	// ↑&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	environment&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	checking_data&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; etc&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;synthesise_expression&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	expression&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ezno_parser&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ast&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Expression&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;	// ↓&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	expected_type&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;	// ↑&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	environment&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	checking_data&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; etc&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So in the above example, we pass the &lt;em&gt;resolved&lt;/em&gt; type in the variable&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;synthesise_variable_declaration&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	variable_declaration&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ezno_parser&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ast&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Expression&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;	// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; expected_type &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;synthesise_type_annotation&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(variable_declaration&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;type_annotation, &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;/* ... */&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;synthesise_expression&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(variable_declaration&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;expression, expected_type, &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;/* ... */&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;	// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;synthesise_variable_declaration&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	variable_declaration&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ezno_parser&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ast&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Expression&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;	// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; expected_type &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;synthesise_type_annotation&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(variable_declaration&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;type_annotation, &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;/* ... */&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;synthesise_expression&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(variable_declaration&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;expression, expected_type, &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;/* ... */&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;	// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We do this passing in several places&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Variable declarations pass their resolved annotation&lt;/li&gt;
&lt;li&gt;Function arguments pass there respective parameter type&lt;/li&gt;
&lt;li&gt;The resolved function return type annotation is stored in the environment and passed to the expression in &lt;code&gt;return&lt;/code&gt; statements&lt;/li&gt;
&lt;li&gt;&lt;code&gt;satisfies&lt;/code&gt; passes its RHS annotation to the LHS. (so technically not forwards. Another to add to my gripes on the &lt;code&gt;satisfies&lt;/code&gt; operator :weary:)&lt;/li&gt;
&lt;li&gt;Class declarations with an &lt;code&gt;implements&lt;/code&gt; clause (&lt;code&gt;extends&lt;/code&gt; is contraversial)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When we arrive at a function or method declaration &lt;strong&gt;and&lt;/strong&gt; this type is a function, we pass the expected parameter types forward to &lt;code&gt;synthesise_function&lt;/code&gt;. When synthesising parameters if we arrive at a parameter without an annotation, we can pick it from the expected parameter.&lt;/p&gt;
&lt;h4 id=&quot;forward-inference-on-properties-gives-unexpected-member-warnings-for-free&quot; tabindex=&quot;-1&quot;&gt;Forward inference on properties gives unexpected member warnings for free&lt;/h4&gt;
&lt;p&gt;We do some transformation and passing in some cases. For example on object literals we get the property on the expected type&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;myobj&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;mymethod&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// we evaluate `{ mymethod: (p: string) =&amp;gt; string }[&amp;quot;mymethod&amp;quot;]` to get the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// expected type of `(p: string) =&amp;gt; string`. The un-annoted parameter `p` &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// therefore has a type of `string`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//       ↓&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;mymethod&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		p &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ← string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;myobj&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;mymethod&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// we evaluate `{ mymethod: (p: string) =&amp;gt; string }[&amp;quot;mymethod&amp;quot;]` to get the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// expected type of `(p: string) =&amp;gt; string`. The un-annoted parameter `p` &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// therefore has a type of `string`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//       ↓&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;mymethod&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		p &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ← string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After adding the inference here, I had an an idea about &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/42#issuecomment-2067326659&quot;&gt;how to add in the comment on an issue&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thanks to the work of &lt;a href=&quot;https://github.com/PatrickLaflamme&quot;&gt;Patrick Laflamme&lt;/a&gt; who implemented this in &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/139&quot;&gt;PR #139&lt;/a&gt; we can raise an early error for excess properties.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; property &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; environment&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get_property&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	expected,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Publicity&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Public&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;key,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; property&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_none&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	checking_data&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;diagnostics_container&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;add_warning&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeCheckWarning&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExcessProperty&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; property &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; environment&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get_property&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	expected,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Publicity&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Public&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;key,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; property&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_none&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	checking_data&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;diagnostics_container&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;add_warning&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeCheckWarning&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExcessProperty&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/PatrickLaflamme/ezno/blob/854f5e832b7729580a3180935241c656f8b3d31f/checker/src/synthesis/expressions.rs#L1061-L1088&quot;&gt;Currently implementation here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;
&lt;p&gt;There are several decisions we take for the expected type for different kinds of expressions.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For assignments we use the constraint (variable or property type) on the LHS&lt;/li&gt;
&lt;li&gt;For conditionals we pass the expected type to both branches&lt;/li&gt;
&lt;li&gt;For object spreads we pass down the whole expected type&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;The last two &lt;a href=&quot;https://kaleidawave.github.io/ezno/comparison/#excesspropertychecksthroughspreadandcondition&quot;&gt;assist in catching excess-property cases that for an unknown reason TypeScript doesn&#39;t catch&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;complications&quot; tabindex=&quot;-1&quot;&gt;Complications&lt;/h4&gt;
&lt;p&gt;One of the problems is around generics. Sometimes we might have a parameter that is based on generics.&lt;/p&gt;
&lt;p&gt;For example &lt;code&gt;addEventListener&lt;/code&gt;, the second function parameter is based of the first argument.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;EventMap&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;mousedown&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;MouseEvent&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Node&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;EventMap&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;cb&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;EventMap&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;EventMap&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;mousedown&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;MouseEvent&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Node&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;EventMap&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;cb&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;EventMap&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can do this by specialising generics left-to-right before the next parameter. This is &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/236&quot;&gt;and some more and currently unimplemented&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;One neat example I forgot I got working is computed generics! &lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=9fm77k&quot;&gt;Here&lt;/a&gt; we get a union of the members, not just &lt;code&gt;number&lt;/code&gt;. (more explanation in the future).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;x.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (a satisfies string, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Expected string, found 1 | 2 | 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;x.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (a satisfies string, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Expected string, found 1 | 2 | 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, there are cases where forward is not enough&lt;/p&gt;
&lt;h4 id=&quot;wrong-direction&quot; tabindex=&quot;-1&quot;&gt;Wrong direction&lt;/h4&gt;
&lt;p&gt;One of the problems with this simple &lt;em&gt;forward pass&lt;/em&gt; is when things are not forwards.&lt;/p&gt;
&lt;p&gt;For example if we have functions of the form&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;cb&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;EventKind&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;kind&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {}, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;mousedown&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;cb&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;EventKind&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;kind&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {}, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;mousedown&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We do not know the expected type of the first paramter, until we have looked at the second parameter.&lt;/p&gt;
&lt;p&gt;Similarily if we write our function outside of the context of usage. Because forwards runs in the same direction as checking we cannot infer &lt;code&gt;ev&lt;/code&gt; here until afterwards.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;doWhenMouseDown&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;document.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;mousedown&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, doWhenMouseDown);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;doWhenMouseDown&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;document.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;mousedown&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, doWhenMouseDown);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;While the forward single pass has a ceiling, there are ways to performance inference above this.&lt;/p&gt;
&lt;h3 id=&quot;backward-inference&quot; tabindex=&quot;-1&quot;&gt;Backward inference&lt;/h3&gt;
&lt;p&gt;This is the harder and still work-in-progress kind of inference. It is also something new, an interpolation inside of existing TypeScript.&lt;/p&gt;
&lt;p&gt;Where forwards involves &lt;strong&gt;context&lt;/strong&gt; on the written parameter, backwards involves &lt;strong&gt;usage&lt;/strong&gt; of the reference to the parameter.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;sin&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;parameter&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;property&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; parameter.value; &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// require the `parameter` to have a property under key `value`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;sin&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(property) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// require `parameter.property` to have type `number`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;sin&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;parameter&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;property&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; parameter.value; &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// require the `parameter` to have a property under key `value`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;sin&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(property) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// require `parameter.property` to have type `number`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;This feature has been implemented before &lt;a href=&quot;https://hegel.js.org/docs#benefits-and-disadvantages-over-typescript&quot;&gt;in the Hegel type checker&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The idea here is that &lt;strong&gt;usage&lt;/strong&gt; of the value adds requirements to the &lt;em&gt;constraint&lt;/em&gt; of the parameter (or any of its descendents).&lt;/p&gt;
&lt;p&gt;You can see attempt #2 &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/197&quot;&gt;working in a branch I started last year&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This is attempt #2 at the feature. Attempt &lt;a href=&quot;https://kaleidawave.github.io/posts/introducing-ezno/#free-variables-(hidden-parameters)-of-functions&quot;&gt;#1 was partially working 3 years ago&lt;/a&gt;, but the implementation required mutating the parameter type during checking of the body, which caused all sort of problems. This new one pushes a sequence of requirement or constraints to the current context. At the end of checking the body, these requirements are collapsed into a final type.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;steps-for-backward-inference-landing-in-0.1.0&quot; tabindex=&quot;-1&quot;&gt;Steps for backward inference landing in &lt;code&gt;0.1.0&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;While three of the &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/197/files#diff-8a0b8f92efee334818b42e62974af189aecb8ac866f988815040531489bb7062&quot;&gt;fundamental tests are passing&lt;/a&gt;, there is still a bit more to do to move this from a demonstration to something that could make writing real-world type-safe code easier.&lt;/p&gt;
&lt;p&gt;The first is to collect more examples of &lt;a href=&quot;https://github.com/kaleidawave/ezno/discussions/195&quot;&gt;untyped code&lt;/a&gt;, to see whether there are more cases to collect and implement.&lt;/p&gt;
&lt;p&gt;One of those is the cases is free-variables. Ezno does not infer constraints for variable in standard flow (which is a whole other topic). But when a variable crosses a function boundary, there is some special handling under the title of &lt;em&gt;free-variables&lt;/em&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;initialiseA&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;doThing&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;initialiseA&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;doThing&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here &lt;code&gt;doThing&lt;/code&gt; requires &lt;code&gt;a&lt;/code&gt; to be &lt;code&gt;string&lt;/code&gt; (not &lt;code&gt;null&lt;/code&gt;). Some assignment needs to happen before any calls to &lt;code&gt;doThing&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The inference can treat find requirements for free variables (treating them the same as parameters), but currently attempt #2 checking for these constraints. Attempt #1 &lt;a href=&quot;https://kaleidawave.github.io/posts/introducing-ezno/#free-variables-(hidden-parameters)-of-functions&quot;&gt;did do this&lt;/a&gt; but I have concerns about performing this eagerly...&lt;/p&gt;
&lt;p&gt;Another is conditionals, this is something attempt #1 could not achieve because of the mutations. Here &lt;code&gt;item&lt;/code&gt; should infer as &lt;code&gt;{ tag: &amp;quot;a&amp;quot;, data: number } | { tag: &amp;quot;b&amp;quot;, data: string }&lt;/code&gt; rather than &lt;code&gt;{ tag: any, data: string &amp;amp; number }&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (item.tag &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;a&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a.data;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (item.tag &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;b&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a.data;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (item.tag &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;a&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a.data;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (item.tag &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;b&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a.data;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;allowing-valid-javascript%2C-with-new-intrinsics&quot; tabindex=&quot;-1&quot;&gt;Allowing valid JavaScript, with new intrinsics&lt;/h4&gt;
&lt;p&gt;One of the aims of this feature is to allow JavaScript code to be checked. Here we want to catch &lt;strong&gt;false-negatives&lt;/strong&gt;, errors that occur at runtime but are uncaught by the checker. But we also have to consider this could introduce &lt;strong&gt;false-positives&lt;/strong&gt;. For example &lt;code&gt;Math.sin(&amp;quot;2.2&amp;quot;)&lt;/code&gt; is totally valid, the string &amp;quot;2.2&amp;quot; can be passed and we do not get an error (Infact it returns &lt;code&gt;0.808...&lt;/code&gt; as the function performs an implict cast). In fact any value passed to the &lt;code&gt;Math.sin&lt;/code&gt; is valid (unless its &lt;code&gt;toPrimitive&lt;/code&gt; throws). In the following, one argument is a &lt;code&gt;number&lt;/code&gt; &lt;em&gt;type&lt;/em&gt; and another &lt;em&gt;is not&lt;/em&gt;, yet we get identical output...&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;sin&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// NaN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;sin&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {})) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// (also) NaN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;sin&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// NaN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;sin&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {})) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// (also) NaN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Currently the second call is outlawed by the rules TypeScript, which &lt;em&gt;technically&lt;/em&gt; does not make a JavaScript superset...&lt;/p&gt;
&lt;p&gt;In a previous post I outlined some &lt;a href=&quot;https://kaleidawave.github.io/posts/experimental-types/&quot;&gt;intrinsic types&lt;/a&gt; I added to the checker. These are types different to the standard root, union, interesection, generic etc types in that they have specific behavior for a situation. Most of them narrow down on some type, such as &lt;a href=&quot;https://kaleidawave.github.io/posts/experimental-types#multipleof&quot;&gt;&lt;code&gt;MultipleOf&lt;/code&gt;&lt;/a&gt; that only allows numbers that are of some multiple to be passed. Some like TSCs &lt;code&gt;NoInfer&lt;/code&gt; controls behavior around inference.&lt;/p&gt;
&lt;p&gt;So a solution we could invent here is a new intrinsic type called &lt;code&gt;Warn&lt;/code&gt;. This could have a type and tag associated with it. When the checker see that the RHS of the subtype matches the first type argument we could allow it but also emit an error that it was matched.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;NumberLike&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Warn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;implicit cast&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//                         ^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;sin&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;NumberLike&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;declare&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Warning (not error): &amp;quot;2.2&amp;quot; is allowed but is a &amp;quot;implicit cast&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;sin&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;2.2&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;NumberLike&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Warn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;implicit cast&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//                         ^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;sin&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;NumberLike&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;declare&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Warning (not error): &amp;quot;2.2&amp;quot; is allowed but is a &amp;quot;implicit cast&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;sin&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;2.2&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Any suggestions: for the name, usage etc are welcome on &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/235&quot;&gt;this issue&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Then anything inferred from the argument passing would be valid as it currently &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/d4142fe9471e688e2c03b228d6ecb7b8fde1b236/checker/specification/staging.md#from-argument&quot;&gt;can create a false posiitive&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;wrapping-up&quot; tabindex=&quot;-1&quot;&gt;Wrapping up&lt;/h3&gt;
&lt;p&gt;There are still somethings to say about what backward inference can solve, but I will cut it here on the ideas and share them once it works.&lt;/p&gt;
&lt;p&gt;You can read about &lt;a href=&quot;https://kaleidawave.github.io/posts/specification-speed-schedule/#schedule&quot;&gt;when the next release will be in the previous blog post&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you want to see more of this kind of thing you can follow me on &lt;a href=&quot;https://x.com/kaleidawave&quot;&gt;x&lt;/a&gt;, &lt;a href=&quot;https://bsky.app/profile/kaleidawave.bsky.social&quot;&gt;bluesky&lt;/a&gt; and &lt;a href=&quot;https://github.com/sponsors/kaleidawave&quot;&gt;join the existing great sponsors of the project!&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Specification, speed and (a) schedule</title>
    <link href="https://kaleidawave.github.io/posts/specification-speed-schedule/"/>
    <updated>2025-09-24T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/specification-speed-schedule/</id>
    <summary>356, 11.16 and a future 0.1.0 ?</summary>
    <content xml:lang="en" type="html">&lt;p&gt;It is Ezno week! As it has been three years since the &lt;a href=&quot;https://kaleidawave.github.io/posts/introducing-ezno&quot;&gt;initial announcement&lt;/a&gt; I thought I would publish three blog posts that were lying around and trying to spin this project up again after taking a break this last year.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;To recap Ezno is &amp;quot;A fast and correct TypeScript type checker and compiler with additional experiments&amp;quot;.&lt;/p&gt;
&lt;p&gt;I started this project because: I wanted to learn more Rust (and to get better at programming on large projects) and I had some interesting ideas about what a type-checker could do.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Also because there were still Coronavirus lockdowns around that time and that was the only thing to do back then.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Three years since the announcement: it has gone from a private demo on a collection of ideas, to a small open-source project. Development currently has been &lt;em&gt;slowly&lt;/em&gt; chipping away at sections of a feature, getting some base cases working, understanding the core abstractions and then experimenting with new ideas.&lt;/p&gt;
&lt;p&gt;Although it is not ready for production, there are many achievements to &lt;em&gt;celebrate&lt;/em&gt; at this &lt;em&gt;checkpoint stage&lt;/em&gt;. This post outlines an overview of some progress since the announcement.&lt;/p&gt;
&lt;h3 id=&quot;specification&quot; tabindex=&quot;-1&quot;&gt;Specification&lt;/h3&gt;
&lt;p&gt;At the announcement, there were no tests for type-checking. Testing a large and continually changing project can unrewarding and laborious. In 2023, I added &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/50&quot;&gt;tests to the project&lt;/a&gt; in the form of a markdown file that is &lt;em&gt;compiled&lt;/em&gt; in to Rust code using the default test harness. This markdown form of tests for type-checking doubles up as readable documentation for the currently supported features as well as being a format that is really easy to add new tests to.&lt;/p&gt;
&lt;p&gt;In the year after, working on more features the number of tests went from around 30 to around 350.&lt;/p&gt;
&lt;p&gt;The latest iteration of this markdown-testing idea has been in &lt;a href=&quot;https://github.com/kaleidawave/experiments/pull/2&quot;&gt;a standalone tool called &lt;em&gt;spectra&lt;/em&gt;&lt;/a&gt;. It is currently still as an experiement or a canary release but I have been using it with great success on &lt;a href=&quot;https://github.com/kaleidawave/simple-json-parser/blob/improvements/specification.md&quot;&gt;several&lt;/a&gt; &lt;a href=&quot;https://github.com/kaleidawave/simple-toml-parser/blob/improvements/specification.md&quot;&gt;of&lt;/a&gt; &lt;a href=&quot;https://github.com/kaleidawave/simple-markdown-parser/blob/improvements/tests/specification.md&quot;&gt;my&lt;/a&gt; &lt;a href=&quot;https://github.com/kaleidawave/experiments/blob/general-parser/general-parser/specification.md&quot;&gt;parsers&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;With some recent improvements, &lt;a href=&quot;https://github.com/kaleidawave/ezno/actions/runs/17912411836/job/50926810577#step:10:515&quot;&gt;there are now 356 tests passing on Ezno&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The next step is a &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/230&quot;&gt;&lt;em&gt;v2&lt;/em&gt; of the specification&lt;/a&gt; with general improvements to split the &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/specification/specification.md&quot;&gt;&lt;code&gt;specification.md&lt;/code&gt;&lt;/a&gt; into multiple files and &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/specification-two/specification/02-checker/01-types/03-generics/01-inference-and-substitution.md#implementation&quot;&gt;add more detailed documentation into it&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you have suggestions for documentation, things you think would be good to include you can leave comments on &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/230&quot;&gt;the PR&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;speed&quot; tabindex=&quot;-1&quot;&gt;Speed&lt;/h3&gt;
&lt;p&gt;Building a performant type-checker is a hard task. To get the type systems working in the first place is a challenge on its own but to do that while considering memory usage and eliminating overhead is a whole other level.&lt;/p&gt;
&lt;p&gt;However, it is a benefitial thing to do. For users it can reduce CI costs and buys more space for additional features.&lt;/p&gt;
&lt;p&gt;And as an implementor it is quite an interesting, you learn about lower-level tooling and forces you to revisit previous code.&lt;/p&gt;
&lt;p&gt;Oftenly making code shorter and more simple rewards you with the improved performance without thinking about the details.&lt;/p&gt;
&lt;p&gt;This has been the case with &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/191&quot;&gt;last years parser change&lt;/a&gt;. Moving to a simpler model has brought the parsing way down. Before the change, for large files, the parsing time count was 2-3 times the type-checking time. &lt;a href=&quot;https://x.com/kaleidawave/status/1846238071026487560/photo/1&quot;&gt;After the change the parsing took the same time as type-checking&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;More recently (at the start of this summer), I worked on optimising the layout of structures in the parser. I built a parser for some of the diagnostics you can get out of the &lt;a href=&quot;https://github.com/kaleidawave/experiments/pull/10&quot;&gt;Rust compiler&lt;/a&gt;. Using this tool I could easily find some places where there were enums with variants significantly larger than common constructed forms (clippy does not catch all cases). After some changes I managed to drop memory usage by over half as well as a ~20% reduction in execution time. Comparing these currently &lt;strong&gt;unmerged&lt;/strong&gt; changes against the &lt;code&gt;main&lt;/code&gt; branch, &lt;a href=&quot;https://github.com/kaleidawave/experiments/pull/10&quot;&gt;the CI reports&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;binaries/binary-LinuxX64-main-last/binary-LinuxX64-main-last: 10 837 025 bytes allocated and 44 930 722 instructions&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;binaries/latest/ezno: 4 660 067 bytes allocated and 39 699 629 instructions&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;binaries/binary-LinuxX64-main-last/binary-LinuxX64-main-last: 10 837 025 bytes allocated and 44 930 722 instructions&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;binaries/latest/ezno: 4 660 067 bytes allocated and 39 699 629 instructions&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Summary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  ./binaries/binary-LinuxX64-general-fixes-last/binary-LinuxX64-general-fixes-last check demo.tsx ran&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  1.21 ± 0.02 &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; faster than ./binaries/binary-LinuxX64-main-last/binary-LinuxX64-main-last check demo.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Summary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  ./binaries/binary-LinuxX64-general-fixes-last/binary-LinuxX64-general-fixes-last check demo.tsx ran&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  1.21 ± 0.02 &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; faster than ./binaries/binary-LinuxX64-main-last/binary-LinuxX64-main-last check demo.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is one important part the performance work: to have a open and public log of results that can calculate differences and integrates with the CI checking and so forth.&lt;/p&gt;
&lt;p&gt;GitHub actions is far from perfect, I have been trying to find a more precise and predictable tool to &lt;code&gt;hyperfine&lt;/code&gt; (&lt;em&gt;ironically&lt;/em&gt;). GitHub actions can vary in performance quite a bit and do not have access to systems that require root level access such as &lt;code&gt;perf_events&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Last Friday, I found out about &lt;a href=&quot;https://www.intel.com/content/www/us/en/developer/articles/tool/software-development-emulator.html&quot;&gt;SDE&lt;/a&gt;. I am still learning about it, but effectively it does &lt;em&gt;binary instrumentation&lt;/em&gt; (effectively a CPU emulator) to run a binary while counting various kinds of instructions that have been run. This is perfect as we can see exact counts of instructions &lt;strong&gt;run&lt;/strong&gt; (not emitted) and under different sections of the program. Of course &lt;a href=&quot;https://github.com/kaleidawave/experiments/pull/20&quot;&gt;I then built a parser to analyse the output&lt;/a&gt; and now have it running in the GitHub CI.&lt;/p&gt;
&lt;p&gt;I am still learning what it emits and how to act on it. But recent work on another project found Rust &lt;a href=&quot;https://godbolt.org/z/jcYea4Mhx&quot;&gt;does not collapse a hot path in the lexer&lt;/a&gt;. On my WIP branch I managed to change some things in the lexer to take total instructions &lt;code&gt;28 354 432&lt;/code&gt; instructions to &lt;code&gt;27 286 219&lt;/code&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I will do a dedicated blog post on the parser and the exacts of last years lexer change but there is still more work to do. Similiarly for &amp;quot;monitoring performance in CI&amp;quot;, I still need to learn more about &lt;a href=&quot;https://www.intel.com/content/www/us/en/developer/articles/tool/software-development-emulator.html&quot;&gt;SDE&lt;/a&gt;. Whether it can give more information on memory, why it lists 10 million less instructions run than callgrind, dealing with inlined code, instruction wall-clock time heuristics and maybe adding a &#39;diffing&#39; functionality to my &lt;a href=&quot;https://github.com/kaleidawave/experiments/pull/20&quot;&gt;sde-parsing tool&lt;/a&gt;. If you have tips/experience, leave it in the comments below!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is on top of a the existing general principle of the project of writing minimal code, using a low numbers of dependencies, writing iterators rather than allocating vectors etc.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;So with all these improvements, how is the performance going?&lt;/p&gt;
&lt;p&gt;Well using the &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/specification/specification.md&quot;&gt;specification.md file&lt;/a&gt; &lt;a href=&quot;https://kaleidawave.github.io/posts/specification-speed-schedule/#specification&quot;&gt;from earlier&lt;/a&gt; we can build an amalgamation of examples on the specification. We remove &lt;code&gt;import&lt;/code&gt; and &lt;code&gt;export&lt;/code&gt; examples as we want to compile it to a single file and we do some transformations so there are no clashes with names. The &lt;a href=&quot;https://en.wikipedia.org/wiki/Text_corpus&quot;&gt;corpus&lt;/a&gt; contains a breadth of features (and so tests a wide range of behaviors that could exist in a program) and now with 356 (minus module tests) we get around 2k LOC of code to test against. It doesn&#39;t accurately reflect a program, but it alright at this stage. We know running performance results on this file are accurate because the examples covers all features and does not include stuff that is incomplete or can currently crash the checker. &lt;a href=&quot;https://gist.github.com/kaleidawave/81066f322ed574b3373e27770137013f&quot;&gt;You can view the whole file here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;And running in the new CI setup, we see the &lt;strong&gt;latest&lt;/strong&gt; on the &lt;code&gt;general-fixes&lt;/code&gt; branches &lt;a href=&quot;https://github.com/kaleidawave/ezno/actions/runs/17956348682&quot;&gt;runs in around ~10ms&lt;/a&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;This does not mean much on its own, so we can compare it to the most complete type-checkers and here we see an impressive result when checking our 2k LOC example.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Benchmark 1: ./ezno check demo.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Time (mean ± σ):       8.3 ms ±   0.2 ms    [User: 6.3 ms, System: 1.7 ms]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Range (min … max):     8.0 ms …   9.5 ms    316 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Benchmark 2: ./node_modules/@typescript/native-preview-linux-x64/lib/tsgo --noEmit --jsx preserve --skipLibCheck demo.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Time (mean ± σ):      92.1 ms ±   3.5 ms    [User: 119.0 ms, System: 29.3 ms]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Range (min … max):    86.3 ms … 100.4 ms    32 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Benchmark 3: node ./node_modules/typescript/lib/_tsc.js --noEmit --jsx preserve --skipLibCheck demo.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Time (mean ± σ):     772.9 ms ±   6.3 ms    [User: 1451.6 ms, System: 63.3 ms]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Range (min … max):   761.9 ms … 780.4 ms    10 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Summary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  ./ezno check demo.tsx ran&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;   11.16 ± 0.48 &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; faster than ./node_modules/@typescript/native-preview-linux-x64/lib/tsgo --noEmit --jsx preserve --skipLibCheck demo.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;   93.65 ± 2.18 &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; faster than node ./node_modules/typescript/lib/_tsc.js --noEmit --jsx preserve --skipLibCheck demo.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Benchmark 1: ./ezno check demo.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Time (mean ± σ):       8.3 ms ±   0.2 ms    [User: 6.3 ms, System: 1.7 ms]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Range (min … max):     8.0 ms …   9.5 ms    316 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Benchmark 2: ./node_modules/@typescript/native-preview-linux-x64/lib/tsgo --noEmit --jsx preserve --skipLibCheck demo.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Time (mean ± σ):      92.1 ms ±   3.5 ms    [User: 119.0 ms, System: 29.3 ms]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Range (min … max):    86.3 ms … 100.4 ms    32 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Benchmark 3: node ./node_modules/typescript/lib/_tsc.js --noEmit --jsx preserve --skipLibCheck demo.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Time (mean ± σ):     772.9 ms ±   6.3 ms    [User: 1451.6 ms, System: 63.3 ms]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Range (min … max):   761.9 ms … 780.4 ms    10 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Summary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  ./ezno check demo.tsx ran&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;   11.16 ± 0.48 &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; faster than ./node_modules/@typescript/native-preview-linux-x64/lib/tsgo --noEmit --jsx preserve --skipLibCheck demo.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;   93.65 ± 2.18 &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; faster than node ./node_modules/typescript/lib/_tsc.js --noEmit --jsx preserve --skipLibCheck demo.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When we concatenate the file 10 times over, we see a good but slightly less impressive result compared to TSC based compilers (for some reason they does not seem to scale linearly).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Benchmark 1: ./ezno check demo10.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Time (mean ± σ):      72.3 ms ±   1.3 ms    [User: 60.3 ms, System: 11.7 ms]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Range (min … max):    70.3 ms …  78.7 ms    41 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Benchmark 2: ./node_modules/@typescript/native-preview-linux-x64/lib/tsgo --noEmit --jsx preserve --skipLibCheck demo10.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Time (mean ± σ):     476.2 ms ±   9.8 ms    [User: 646.7 ms, System: 69.9 ms]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Range (min … max):   464.1 ms … 496.4 ms    10 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Benchmark 3: node ./node_modules/typescript/lib/_tsc.js --noEmit --jsx preserve --skipLibCheck demo10.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Time (mean ± σ):      1.863 s ±  0.086 s    [User: 4.296 s, System: 0.104 s]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Range (min … max):    1.805 s …  2.082 s    10 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Summary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  ./ezno check demo10.tsx ran&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    6.58 ± 0.18 &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; faster than ./node_modules/@typescript/native-preview-linux-x64/lib/tsgo --noEmit --jsx preserve --skipLibCheck demo10.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;   25.76 ± 1.27 &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; faster than node ./node_modules/typescript/lib/_tsc.js --noEmit --jsx preserve --skipLibCheck demo10.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Benchmark 1: ./ezno check demo10.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Time (mean ± σ):      72.3 ms ±   1.3 ms    [User: 60.3 ms, System: 11.7 ms]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Range (min … max):    70.3 ms …  78.7 ms    41 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Benchmark 2: ./node_modules/@typescript/native-preview-linux-x64/lib/tsgo --noEmit --jsx preserve --skipLibCheck demo10.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Time (mean ± σ):     476.2 ms ±   9.8 ms    [User: 646.7 ms, System: 69.9 ms]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Range (min … max):   464.1 ms … 496.4 ms    10 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Benchmark 3: node ./node_modules/typescript/lib/_tsc.js --noEmit --jsx preserve --skipLibCheck demo10.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Time (mean ± σ):      1.863 s ±  0.086 s    [User: 4.296 s, System: 0.104 s]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Range (min … max):    1.805 s …  2.082 s    10 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Summary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  ./ezno check demo10.tsx ran&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    6.58 ± 0.18 &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; faster than ./node_modules/@typescript/native-preview-linux-x64/lib/tsgo --noEmit --jsx preserve --skipLibCheck demo10.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;   25.76 ± 1.27 &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; faster than node ./node_modules/typescript/lib/_tsc.js --noEmit --jsx preserve --skipLibCheck demo10.tsx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/benchmarks/actions/runs/17978178009&quot;&gt;Full benchmark public here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;With &lt;code&gt;--timings&lt;/code&gt; in Ezno and &lt;code&gt;--diagnostics&lt;/code&gt; in TSC. We can see some a breakdown for these results&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;# in Ezno&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Diagnostics: 4320&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Types:       48667&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Lines:       21990&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Cache read:  205.976µs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;FS read:     1.383218ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Parsed in:   23.138385ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Checked in:  37.645912ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Narrowing:   327.594µs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Reporting:   639.726µs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;# in tsgo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Files:               8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Lines:           61095&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Identifiers:     70224&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Symbols:         50955&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Types:           11370&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Instantiations:   4224&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Memory used:    42754K&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Memory allocs:  793413&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Parse time:     0.059s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Bind time:      0.021s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Check time:     0.392s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Emit time:      0.000s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Total time:     0.509s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;# in Ezno&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Diagnostics: 4320&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Types:       48667&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Lines:       21990&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Cache read:  205.976µs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;FS read:     1.383218ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Parsed in:   23.138385ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Checked in:  37.645912ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Narrowing:   327.594µs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Reporting:   639.726µs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;# in tsgo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Files:               8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Lines:           61095&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Identifiers:     70224&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Symbols:         50955&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Types:           11370&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Instantiations:   4224&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Memory used:    42754K&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Memory allocs:  793413&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Parse time:     0.059s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Bind time:      0.021s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Check time:     0.392s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Emit time:      0.000s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Total time:     0.509s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Again Ezno is currently work-in-progress, so these differences are not usable in code today. But you can see that currently implemented parts are going well.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/microsoft/typescript-go&quot;&gt;tsgo&lt;/a&gt; is great, because it builds something I did not exactly want to build that being: a &lt;em&gt;exact drop-in faster type-checker for use in the near future&lt;/em&gt;. It never made any sense to try and do what is the job of the TSC team for exclusively performance reasons, which is something I have not been too bothered by when writing TypeScript code.&lt;/p&gt;
&lt;p&gt;Instead, I decided to build something different, new and original. Based on learning how it all works, rather than being a human transpiler. Recognising that some of TSCs code has been written a while ago, with different aims. That there are &lt;a href=&quot;https://kaleidawave.github.io/posts/experimental-types/&quot;&gt;new features that can be added in places&lt;/a&gt; and &lt;a href=&quot;https://kaleidawave.github.io/posts/implementing-narrowing/#explicit-type-annotation-type-guards&quot;&gt;existing problems can be fixed by starting from the ground up&lt;/a&gt;. And that at the end of the day you &lt;a href=&quot;https://kaleidawave.github.io/ezno/comparison&quot;&gt;can still maintain some compatability&lt;/a&gt; and &lt;a href=&quot;https://kaleidawave.github.io/posts/mapped-types/&quot;&gt;keep existing features&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;There are a few differences between the type-checkers, firstly the checking behaviour is different in Ezno compared to TSC (&lt;a href=&quot;https://kaleidawave.github.io/ezno/comparison/&quot;&gt;with an aim to get very similar errors&lt;/a&gt;). Ezno is written in &lt;a href=&quot;https://www.rust-lang.org/&quot;&gt;Rust&lt;/a&gt; whereas &lt;a href=&quot;https://github.com/microsoft/typescript-go&quot;&gt;tsgo&lt;/a&gt; is written in &lt;a href=&quot;https://go.dev/&quot;&gt;Golang&lt;/a&gt;. Ezno does not doing anything in parallel currently, but &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/38&quot;&gt;may when it is more mature&lt;/a&gt;. For &lt;code&gt;lib.d.ts&lt;/code&gt; it has a compressed binary form, rather than reading a pseudo-human readable file. &lt;a href=&quot;https://kaleidawave.github.io/posts/ezno-23/#binary-context%2Fdefinition-files&quot;&gt;This drops a lot of initial overhead&lt;/a&gt; as it does not have to deal with hoisting etc. Without &lt;code&gt;--max-diagnostics&lt;/code&gt; being specified, Ezno only &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/c152aed0ca13313a3b1607a04975fce4c7d638a8/src/utilities.rs#L115&quot;&gt;prints the first 30 diagnostics&lt;/a&gt; whereas &lt;code&gt;tsc&lt;/code&gt; prints every error.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Rust and Golang, are very good programming languages especially when building compilers, parsers and other command line programs. It is clear why the TSC team went for Golang with its inbuilt mark-and-sweep garbage collection for there syntactical port. On the other hand, Ezno will continue with its Rust implementation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;a-schedule%3F&quot; tabindex=&quot;-1&quot;&gt;A &lt;em&gt;schedule&lt;/em&gt;?&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;Not quite the right heading, but have to stick to the &#39;s&#39; theme&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This blog post has been a showing a trend in the right direction on the specification tests and performance numbers. This is a hobby project for me, not a job. It has been an &lt;em&gt;extracurricular&lt;/em&gt;, in learning new things and building stuff that I can direct and deem new and useful. I do not set many deadlines and work mostly on things that I think will be fun to work on.&lt;/p&gt;
&lt;p&gt;Events/partial application is the &lt;em&gt;invisible&lt;/em&gt; elephant in the room for usability. I would like to do a talk before the blog post, so if you have meetup in Europe get in contact! I would like to release the blog post on some of the findings within the twelve months. While cool, the events feature is large and complex, which will be hard to scale to large and complex codebases. Before the next &lt;code&gt;0.1.0&lt;/code&gt; release there will be a flag to disable some of the feature and make using external packages infinitely easier.&lt;/p&gt;
&lt;p&gt;For the &lt;a href=&quot;https://kaleidawave.github.io/posts/introducing-ezno/#the-%22framework%22&quot;&gt;framework idea proposed in the initial blog post&lt;/a&gt;, it has not really been worked on since 2022. The improvement to the underlying compiler findings has made it a lot more possible and flexible, so maybe when I find the time I will put out a demonstration of how the type-checking logic can benefit specific parts of front-end code. But it has moved out of the primary focus of the compiler.&lt;/p&gt;
&lt;p&gt;There are three other ideas I want to work on for version &lt;code&gt;0.1.0&lt;/code&gt;. All going well it could be as soon as the end of this year? The &lt;code&gt;0.1.0&lt;/code&gt; release should work (aka catch 95% of type erros) in small low-dependency projects. So I will &lt;em&gt;cut&lt;/em&gt; the release when I have some of my examples working at that level (and not just concatenations of test cases).&lt;/p&gt;
&lt;p&gt;You can star and watch &lt;a href=&quot;https://github.com/kaleidawave/ezno&quot;&gt;the repository&lt;/a&gt; for that announcement and &lt;a href=&quot;https://github.com/sponsors/kaleidawave&quot;&gt;sponsor&lt;/a&gt; to help it fall this side of the new year!&lt;/p&gt;
&lt;p&gt;For more updates you can follow this as &lt;a href=&quot;https://kaleidawave.github.io/feed.xml&quot;&gt;blog as RSS&lt;/a&gt; and follow me on &lt;a href=&quot;https://x.com/kaleidawave&quot;&gt;X&lt;/a&gt; and &lt;a href=&quot;https://bsky.app/profile/kaleidawave.bsky.social&quot;&gt;BlueSky&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Implementing narrowing</title>
    <link href="https://kaleidawave.github.io/posts/implementing-narrowing/"/>
    <updated>2025-09-22T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/implementing-narrowing/</id>
    <summary>Narrowing types</summary>
    <content xml:lang="en" type="html">&lt;p&gt;This post is on implementing the type-narrowing feature from TypeScript into my own type-checker &lt;a href=&quot;https://github.com/kaleidawave/ezno&quot;&gt;ezno&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;what-is-type-narrowing%3F&quot; tabindex=&quot;-1&quot;&gt;What is type narrowing?&lt;/h2&gt;
&lt;p&gt;TypeScript is an extension to JavaScript. In JavaScript every value has a type.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hiya&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// boolean&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { a: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// object&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (() &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hiya&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// boolean&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { a: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// object&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (() &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can reason about values and variables before run-time using type checkers and types annotations.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;print_type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;print_type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(param) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;print_type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;print_type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(param) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There are many places where types annotations can exist. These annotations can inform the checker about the shapes of the values a reference can have so that the checker program can report errors and more ahead of time.&lt;/p&gt;
&lt;p&gt;There are other ways &lt;em&gt;types&lt;/em&gt; are &lt;em&gt;realised&lt;/em&gt; within the checker aside from annotations. One of them is the information present in the assumption of a condition holding in a branching structure.&lt;/p&gt;
&lt;p&gt;Here we see that because of the condition &lt;code&gt;param === &amp;quot;hi&amp;quot;&lt;/code&gt;, we can &lt;strong&gt;narrow&lt;/strong&gt; in on the type string to knowing that value of &lt;code&gt;param&lt;/code&gt; in the branch is a constant string &lt;code&gt;&amp;quot;hi&amp;quot;&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (param &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;print_type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(param) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// &amp;quot;hi&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (param &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;print_type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(param) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// &amp;quot;hi&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;why-type-narrowing%3F&quot; tabindex=&quot;-1&quot;&gt;Why type narrowing?&lt;/h2&gt;
&lt;p&gt;This functionality enables a few things&lt;/p&gt;
&lt;p&gt;1. We can branch on the tags of sum types&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Kinds&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;tag&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;person&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;age&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;tag&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;vehicle&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;horsepower&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;print_kind&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Kinds&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (item.tag &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;vehicle&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;print_type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(item.horsepower)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Kinds&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;tag&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;person&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;age&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;tag&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;vehicle&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;horsepower&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;print_kind&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Kinds&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (item.tag &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;vehicle&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;print_type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(item.horsepower)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;2. We can &lt;em&gt;filter&lt;/em&gt; out &lt;code&gt;null&lt;/code&gt; values through early returns&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;print&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;MyObject&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (item &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(item.name)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;print&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;MyObject&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (item &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(item.name)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and through short-circuiting operators&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;contains&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;blue&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;contains&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;blue&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;3. We can detect exact values (here through a free-variable)&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;print&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Warning here!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;print&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Warning here!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;4. Checking data exterior to the program&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;./my_api.json&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; item.property &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(item.property);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;./my_api.json&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; item.property &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(item.property);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Effectively it enables&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Using properties of data of varying structure&lt;/li&gt;
&lt;li&gt;Using properties of data of unknown types&lt;/li&gt;
&lt;li&gt;Catching truthy values&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;p&gt;The idea behind narrowing is to pick a new type (that is a subset of the current type) based on properties enforced by the condition.&lt;/p&gt;
&lt;p&gt;We can do that given we have in the context&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Some &lt;em&gt;unknown&lt;/em&gt; type: parameter or from some external source.&lt;/li&gt;
&lt;li&gt;A conditional expression&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;information-on-types&quot; tabindex=&quot;-1&quot;&gt;Information on types&lt;/h2&gt;
&lt;p&gt;Now we know what narrowing is and why it exists as a feature, we can see how we may go about implementing it.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Ezno is not a rewrite or port of the TypeScript Compiler (TSC), so this implemention was built on my own intuition and may be completely different to how it is built in TSC. We can see thought that it &lt;a href=&quot;https://kaleidawave.github.io/ezno/comparison/##narrowing&quot;&gt;matches much of the same functionality of TSC&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;
&lt;p&gt;The first thing to know is how Ezno represents types. Here parameter types and external types are &lt;em&gt;wrapped&lt;/em&gt; in special types similar to generics. These wrapper types therefore have a flag and as they are &lt;em&gt;new&lt;/em&gt; types, a unique &lt;code&gt;TypeId&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;#5: string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;#1232: Parameter { name: &amp;quot;param&amp;quot;, backing: #5 }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;#5: string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;#1232: Parameter { name: &amp;quot;param&amp;quot;, backing: #5 }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When we use a parameter type we add more information onto it. These information is achieved under &lt;code&gt;Constructor&lt;/code&gt;. So &lt;code&gt;param === &amp;quot;hi&amp;quot;&lt;/code&gt; and &lt;code&gt;param.length&lt;/code&gt; become &lt;code&gt;Constructor::Operation { operation: StrictEqual, lhs: #1232, rhs: *&amp;quot;hi&amp;quot;* }&lt;/code&gt; and &lt;code&gt;Constructor::Property { lhs: #1232, rhs: *&amp;quot;length&amp;quot;* }&lt;/code&gt; respectively. We can reduce these constructors to their base types of &lt;code&gt;boolean&lt;/code&gt; and &lt;code&gt;number&lt;/code&gt; when using them but storing them, we hold onto these richer properties.&lt;/p&gt;
&lt;h2 id=&quot;narrowing%3A-the-implementation&quot; tabindex=&quot;-1&quot;&gt;Narrowing: the implementation&lt;/h2&gt;
&lt;p&gt;The main &lt;strong&gt;narrow&lt;/strong&gt; function takes the type of the expression and returns a list of new constraints for various values.&lt;/p&gt;
&lt;p&gt;For example given our above example, we have something like these (described in TypeScript rather than Rust).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;narrow&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;expression&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Parameter&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Constructor&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) -&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Id&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;narrow&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;c &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [[&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Constant&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;narrow&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;expression&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Parameter&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Constructor&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) -&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Id&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;narrow&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;c &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [[&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Constant&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Producing a narrowed map is implemented in the single file &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/src/features/narrowing.rs&quot;&gt;&lt;code&gt;checker/src/features/narrowing.rs&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The &lt;code&gt;narrow&lt;/code&gt; implementation is quite simple: we take our &lt;code&gt;Parameter&lt;/code&gt; and &lt;code&gt;Constructor&lt;/code&gt; objects and figure out narrowed type-to-type key-value entries in our returned map.&lt;/p&gt;
&lt;h3 id=&quot;operator-constructors&quot; tabindex=&quot;-1&quot;&gt;Operator &lt;code&gt;Constructor&lt;/code&gt;s&lt;/h3&gt;
&lt;p&gt;There are many kinds of expressions that give more information about values&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;a &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// a is truthy&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// a now has the type of the RHS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// a now has a type defined by &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;a[prop] &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// a has prop of type&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;prop &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// a has a prop&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;instanceof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// a is an object with prototype&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;a &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// a is truthy&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// a now has the type of the RHS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// a now has a type defined by &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;a[prop] &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// a has prop of type&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;prop &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// a has a prop&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;instanceof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// a is an object with prototype&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here each has types that are structured as&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;*parameter*&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Constructor::Equal { lhs: *parameter*, rhs: ? }&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Constructor::Equal { lhs: Constructor::TypeOf { operand: *parameter* }, rhs: ? }&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Constructor::Equal { lhs: Constructor::Propery { operand: *parameter*, property: *prop* }, rhs: ? }&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Constructor::HasProperty { lhs: *parameter*, rhs: *prop* }&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Constructor::InstanceOf { lhs: *parameter*, rhs: ? }&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When we are passed one of these constructors we can return a key value pair. There is more going on but it is almost as simple as the following&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;narrow&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(ty&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;HashMap&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;	// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Constructor&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;InstanceOf&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { lhs, rhs } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ty_object {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;HashMap&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;from_iter&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;([(lhs, rhs)]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;	// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;narrow&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(ty&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;HashMap&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;	// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Constructor&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;InstanceOf&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { lhs, rhs } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ty_object {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;HashMap&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;from_iter&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;([(lhs, rhs)]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;	// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;While roots are relatively simple, we have to do a bit more when the &lt;code&gt;lhs&lt;/code&gt; is a union type.&lt;/p&gt;
&lt;h3 id=&quot;union-filtering&quot; tabindex=&quot;-1&quot;&gt;Union filtering&lt;/h3&gt;
&lt;p&gt;If we have &lt;code&gt;x: string | number&lt;/code&gt; (a union type) and a check of &lt;code&gt;typeof x === &amp;quot;string&amp;quot;&lt;/code&gt;, we want to find types from the &lt;code&gt;[string, number]&lt;/code&gt; vector that pass the check (in this case &lt;code&gt;string&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Union types are represented as trees, so we do a &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/01b1fd1368d008059abd20111ea38a788304b156/checker/src/features/narrowing.rs#L635&quot;&gt;recursive walk yielding types that pass the filter to a &lt;code&gt;found&lt;/code&gt; array&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;There are (currently) six kinds of filter&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;HasProperty&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HasPrototype&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;IsType&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;null | undefined&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Falsy&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;code&gt;Not&amp;lt;Filter&amp;gt;&lt;/code&gt;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These each yield &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt; for each type passed by the filter. If &lt;code&gt;true&lt;/code&gt; we add that field to vector to build the new, filtered union type.&lt;/p&gt;
&lt;h3 id=&quot;logical-operations%3A-appending-ands&quot; tabindex=&quot;-1&quot;&gt;Logical operations: appending ands&lt;/h3&gt;
&lt;p&gt;Conditions can be combined. One of those is the logical and &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, which can requires the two operands to hold.&lt;/p&gt;
&lt;p&gt;To narrow these we collect each side and concatenate the left cases with the right cases. Here &lt;code&gt;isNumber(a) -&amp;gt; a is number&lt;/code&gt; and &lt;code&gt;isString(b) -&amp;gt; b is string&lt;/code&gt; get combined to yield a narrowed result of &lt;code&gt;isNumber(a) &amp;amp;&amp;amp; isString(b) -&amp;gt; [a is number, b is string]&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;isNumber&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(a) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;isString&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(b)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	a &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// is number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	b &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// is string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;isNumber&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(a) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;isString&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(b)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	a &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// is number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	b &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// is string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;logical-operations%3A-or&quot; tabindex=&quot;-1&quot;&gt;Logical operations: or&lt;/h3&gt;
&lt;p&gt;The other logical operator is the inclusive or: &lt;code&gt;||&lt;/code&gt;. This requires a bit more handling. The following if body can run with &lt;code&gt;a is boolean&lt;/code&gt; and &lt;code&gt;b is string&lt;/code&gt; therefore we can make no conclusions about &lt;code&gt;a&lt;/code&gt; (and vice versa).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;isNumber&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(a) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;isString&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(b)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	a &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// is ?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	b &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// is ?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;isNumber&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(a) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;isString&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(b)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	a &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// is ?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	b &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// is ?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Here we find the keys of the narrowed maps to be disjoint and so produce an empty narrowed map&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;However, if both operands of the logical operator yield a key-value pair for the same LHS parameter type we can &lt;em&gt;union&lt;/em&gt; the results.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;isNumber&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(x) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;isString&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(x)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	x &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// is number or x is string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;isNumber&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(x) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;isString&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(x)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	x &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// is number or x is string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;x is number --&#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;			   |---&amp;gt; x is number | string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;x is string --/			   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;x is number --&#92;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;			   |---&amp;gt; x is number | string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;x is string --/			   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;You can see this merging &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/01b1fd1368d008059abd20111ea38a788304b156/checker/src/features/narrowing.rs#L432-L433&quot;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;logical-operators%3A-negation-operators&quot; tabindex=&quot;-1&quot;&gt;Logical operators: negation operators&lt;/h3&gt;
&lt;p&gt;The final logical operation is negation. We control this through an additional parameter in our &lt;code&gt;narrow&lt;/code&gt; function. When the &lt;code&gt;negate&lt;/code&gt; parameter is &lt;code&gt;true&lt;/code&gt; it mostly disables narrowing, but as we will see later we it can be useful with additional intrinsic types.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		x &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// is not 3?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		x &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// is not 3?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Negation is not always through the bash (&lt;code&gt;!&lt;/code&gt;) operator. We sometimes see it crop up implicitly through &lt;code&gt;else&lt;/code&gt; branches.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;isNumber&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(x)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	x &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// is not number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// as this is equivalent to&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;isNumber&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(x)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;isNumber&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(x)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	x &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// is not number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;isNumber&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(x)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	x &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// is not number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// as this is equivalent to&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;isNumber&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(x)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;isNumber&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(x)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	x &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// is not number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;logical-operators%3A-de-morgan&#39;s-laws&quot; tabindex=&quot;-1&quot;&gt;Logical operators: De Morgan&#39;s laws&lt;/h3&gt;
&lt;p&gt;We can combine negation with the &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt; operators. Those familiar with &lt;a href=&quot;https://en.wikipedia.org/wiki/De_Morgan%27s_laws&quot;&gt;De Morgan&#39;s laws&lt;/a&gt; may know what we can do here.&lt;/p&gt;
&lt;p&gt;If we have a &lt;code&gt;!(a || b)&lt;/code&gt;, we can treat it as &lt;code&gt;!a &amp;amp;&amp;amp; !b&lt;/code&gt;. So for the following we find the following value for &lt;code&gt;x&lt;/code&gt; in the else branch&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	x &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// is not 2 and not 10&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	x &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// is not 2 and not 10&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;This can be seen &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/01b1fd1368d008059abd20111ea38a788304b156/checker/src/features/narrowing.rs#L403-L409&quot;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;We have the same logic for treating &lt;code&gt;!(a &amp;amp;&amp;amp; b)&lt;/code&gt; as &lt;code&gt;!a &amp;amp;&amp;amp; !b&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;aside%3A-logical-operation-representation&quot; tabindex=&quot;-1&quot;&gt;Aside: logical operation representation&lt;/h3&gt;
&lt;p&gt;For those who may be digging through the code wondering where &lt;code&gt;Constructor::LogicalOr&lt;/code&gt; or &lt;code&gt;Constructor::LogicalNegation&lt;/code&gt; is. There is a interesting &lt;em&gt;short-cut&lt;/em&gt; taken by the compiler in representing these types.&lt;/p&gt;
&lt;p&gt;We do this by realising the following.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;b     ≡ b &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; y ≡ x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; y;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; y ≡ x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;b     ≡ b &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; y ≡ x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; y;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; y ≡ x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So the actual represention of these types is &lt;code&gt;Constructor::ConditionalResult&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Sometimes we want this &lt;em&gt;lifted&lt;/em&gt; form, so there are &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/01b1fd1368d008059abd20111ea38a788304b156/checker/src/types/mod.rs#L476&quot;&gt;helper methods&lt;/a&gt; for finding these.&lt;/p&gt;
&lt;h3 id=&quot;control-flow&quot; tabindex=&quot;-1&quot;&gt;Control flow&lt;/h3&gt;
&lt;p&gt;As mentioned above, when checking the &lt;code&gt;else&lt;/code&gt; branch, we take the &lt;code&gt;condition&lt;/code&gt; in the truthy and run narrowing again with &lt;code&gt;negate = true&lt;/code&gt; this time.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ↓ ↓ ↓&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; negate &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ↑ ↑ ↑&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; values &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;super&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;narrowing&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;narrow_based_on_expression_into_vec&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	condition,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;	// passed here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	negate,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	environment,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; checking_data&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;types,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;options,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ↓ ↓ ↓&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; negate &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ↑ ↑ ↑&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; values &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;super&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;narrowing&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;narrow_based_on_expression_into_vec&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	condition,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;	// passed here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	negate,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	environment,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; checking_data&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;types,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;options,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;This may be duplicate type scanning and &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/193&quot;&gt;maybe could be made faster in the future&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;building-new-objects&quot; tabindex=&quot;-1&quot;&gt;Building new objects&lt;/h3&gt;
&lt;p&gt;For the following&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; obj.property &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; obj.property &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We build up a new object &lt;code&gt;{ property: number }&lt;/code&gt; for &lt;code&gt;obj&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;what-to-do-with-the-narrowed-values%3F&quot; tabindex=&quot;-1&quot;&gt;What to do with the narrowed values?&lt;/h2&gt;
&lt;p&gt;Now we have a map of narrowed values, we then store these on the context local to the branch body.&lt;/p&gt;
&lt;p&gt;At several stages, when using the reference, we &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/01b1fd1368d008059abd20111ea38a788304b156/checker/src/context/mod.rs#L1016&quot;&gt;swap out the backing type with a narrowed value from the context&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;crate&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get_value_of_variable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;	/// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; current_value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; current_value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;or_else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; fact&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;variable_current_value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;on)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;copied&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(current_value) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; current_value {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;		// info = property on context&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; narrowed &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; info&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get_narrowed_or_object&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(current_value, types); &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(narrowed) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; narrowed {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(narrowed);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		} &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(current_value);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;	/// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;crate&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get_value_of_variable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;	/// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; current_value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; current_value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;or_else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; fact&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;variable_current_value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;on)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;copied&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(current_value) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; current_value {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;		// info = property on context&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; narrowed &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; info&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get_narrowed_or_object&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(current_value, types); &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(narrowed) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; narrowed {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(narrowed);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		} &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(current_value);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;	/// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thus concluding how narrowing is implemented:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Have types that store information about operators etc&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Visit&lt;/em&gt; the condition type, producing a map of narrowed constraints. Apply logical operator rules and run filters&lt;/li&gt;
&lt;li&gt;Store that information in the branch context&lt;/li&gt;
&lt;li&gt;When looking up a type of variable etc, look for a narrowed type&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;more-narrowing&quot; tabindex=&quot;-1&quot;&gt;More narrowing&lt;/h2&gt;
&lt;p&gt;We have covered that basics of narrowing. Here are some other interesting things I also implemented.&lt;/p&gt;
&lt;h3 id=&quot;explicit-type-annotation-type-guards&quot; tabindex=&quot;-1&quot;&gt;Explicit type annotation type guards&lt;/h3&gt;
&lt;p&gt;While we can write expression type guards, sometimes this functionality is hidden behind functions. To do this we have &lt;a href=&quot;https://www.typescriptlang.org/docs/handbook/advanced-types.html#typeof-type-guards&quot;&gt;return type guards&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;isNumber&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;is&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;isNumber&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;is&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This works simply again with &lt;code&gt;x&lt;/code&gt; being an implict generic. For &lt;code&gt;x is y&lt;/code&gt; type annotations, we look up the parameter type of &lt;code&gt;x&lt;/code&gt; and &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/01b1fd1368d008059abd20111ea38a788304b156/checker/src/synthesis/type_annotations.rs#L728-L751&quot;&gt;use that type&lt;/a&gt;. At usage, this is done by specialisation like other generics.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The checker has not be tested on schema libraries like &lt;a href=&quot;https://arktype.io/&quot;&gt;arktype&lt;/a&gt; or &lt;a href=&quot;https://zod.dev/&quot;&gt;zod&lt;/a&gt; which use return type guards. Other features of the type system are missing to support this&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;These type guards are synthesised as annotations into a constructor not producible from JavaScript expressions (at the moment 👀). However, because of the &lt;code&gt;Constructor&lt;/code&gt; type, we get &lt;a href=&quot;https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#inferred-type-predicates&quot;&gt;inferred type guards for free&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We also can &lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=9plseg&quot;&gt;check them&lt;/a&gt; (a feature TypeScript does not currently have).&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/guard-checking.png&quot; alt=&quot;guard checking&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This is &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/01b1fd1368d008059abd20111ea38a788304b156/checker/src/types/subtyping.rs#L1201-L1239&quot;&gt;implemented in type subtyping&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;inference-of-not-intrinsic&quot; tabindex=&quot;-1&quot;&gt;Inference of &lt;code&gt;Not&lt;/code&gt; intrinsic&lt;/h3&gt;
&lt;p&gt;Ezno has additional types that can represent things not possible in TypeScript. One of those is the &lt;code&gt;Not&amp;lt;Type&amp;gt;&lt;/code&gt;. &lt;a href=&quot;https://kaleidawave.github.io/posts/experimental-types/&quot;&gt;You can read more about these additional types in a previous post&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;With the &lt;code&gt;Not&lt;/code&gt; intrinsic generated by narrowing &lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=9q89hk&quot;&gt;we can find invariants in the program&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/narrowing-not.png&quot; alt=&quot;narrow-not&quot; /&gt;&lt;/p&gt;
&lt;h3 id=&quot;inference-of-other-number-intrinsics&quot; tabindex=&quot;-1&quot;&gt;Inference of other number intrinsics&lt;/h3&gt;
&lt;p&gt;We can also do this &lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=8vn0g0&quot;&gt;for numbers&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/narrowing-numbers.png&quot; alt=&quot;narrowing-numbers&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/posts/experimental-types/&quot;&gt;Again find out more about these additional types in the previous &#39;experimental types&#39; post&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;performance-and-type-overhead-concerns&quot; tabindex=&quot;-1&quot;&gt;Performance and type overhead concerns&lt;/h3&gt;
&lt;p&gt;Current benchmarking shows roughly &lt;code&gt;1%&lt;/code&gt; of checking time is on building the narrowing map.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;Diagnostics: 4320&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;Types:       48667&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;Lines:       21990&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;Cache read:  231.702µs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;FS read:     1.620879ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;Parsed in:   28.493175ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;Checked in:  43.683541ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;Narrowing:   400.151µs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;Reporting:   903.007µs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;Diagnostics: 4320&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;Types:       48667&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;Lines:       21990&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;Cache read:  231.702µs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;FS read:     1.620879ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;Parsed in:   28.493175ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;Checked in:  43.683541ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;Narrowing:   400.151µs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;Reporting:   903.007µs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The extra intermediate types with deep properties may be a general concern though for performance.&lt;/p&gt;
&lt;h2 id=&quot;wrapping-up&quot; tabindex=&quot;-1&quot;&gt;Wrapping up&lt;/h2&gt;
&lt;p&gt;Hopefully this was interesting short explanation on how I implemented type narrowing. More posts coming soon!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>II lines of code</title>
    <link href="https://kaleidawave.github.io/posts/formatting-and-parsing-numbers/"/>
    <updated>2025-08-14T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/formatting-and-parsing-numbers/</id>
    <summary>On formatting and parsing representations of numbers</summary>
    <content xml:lang="en" type="html">&lt;p&gt;I have been recently working on a few one-off random libraries and tools. Here are a few interesting findings from building one of those: a library for formatting and parsing various representations of numbers.&lt;/p&gt;
&lt;p&gt;This post covers some representations for numbers and how we can write a formatting function &lt;code&gt;u32 -&amp;gt; String&lt;/code&gt; and (the partial inverse of that function) that parses the format &lt;code&gt;String -&amp;gt; u32&lt;/code&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The term &amp;quot;number&amp;quot; in the post refers to a 32-bit or 64-bit fixed point unsigned integer. We will not be covering negative or fractional values for now. Additionally, the theory and logic is the focus of the post but the code and library is written in Rust.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;base-two-and-base-ten&quot; tabindex=&quot;-1&quot;&gt;Base two and base ten&lt;/h3&gt;
&lt;p&gt;Computers work on electricity. They store and transmit numbers through high and low voltages.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/diagrams/binary-wave.svg&quot; alt=&quot;binary-wave&quot; /&gt;&lt;/p&gt;
&lt;p&gt;There are two states high and low. This is known as &lt;strong&gt;bi&lt;/strong&gt;nary with &lt;strong&gt;bi&lt;/strong&gt; &lt;a href=&quot;https://en.wikipedia.org/wiki/Numeral_prefix?wprov=sfti1#Table_of_number_prefixes_in_English&quot;&gt;the numeric prefix for two&lt;/a&gt;. We store each part as a bit. We can store zero as low &lt;code&gt;0&lt;/code&gt; and one as high &lt;code&gt;1&lt;/code&gt;. However, we see the successive number two cannot be represented in one signal. So it becomes in a sequence where we start with  so we shift over to the left. &lt;code&gt;10&lt;/code&gt;. The general pattern is when we add one to a something where the right starts with a zero, we set all trailing ones to zero and set one before said block.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ./format-number 0 --binary         &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ./format-number 6 --binary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;0                                    110&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ./format-number 1 --binary         &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ./format-number 7 --binary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;1                                    111&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ./format-number 2 --binary         &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ./format-number 8 --binary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;10                                   1000&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ./format-number 3 --binary         &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ./format-number 9 --binary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;11                                   1001&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ./format-number 4 --binary         &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ./format-number 10 --binary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;100                                  1010&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ./format-number 5 --binary         &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ./format-number 11 --binary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;101                                  1011&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ./format-number 0 --binary         &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ./format-number 6 --binary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;0                                    110&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ./format-number 1 --binary         &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ./format-number 7 --binary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;1                                    111&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ./format-number 2 --binary         &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ./format-number 8 --binary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;10                                   1000&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ./format-number 3 --binary         &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ./format-number 9 --binary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;11                                   1001&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ./format-number 4 --binary         &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ./format-number 10 --binary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;100                                  1010&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ./format-number 5 --binary         &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ./format-number 11 --binary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;101                                  1011&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We depict these values in fixed amounts such as 32 bits to discern when the line is inactive and when it is representing zeros.&lt;/p&gt;
&lt;p&gt;All formats covered here will have larger-to-smallest for numbers. For example &lt;code&gt;100 &amp;gt; 010 &amp;gt; 001&lt;/code&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;We can represent 2^32^ in 32 bits (4 bytes). Four billion values&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;We can format or print a &lt;code&gt;u32&lt;/code&gt; value (into a &lt;code&gt;String&lt;/code&gt;) through the following.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We calculate how many zero or one characters it takes to represent a number by taking counting leading zeros (equivalent to &lt;code&gt;log2&lt;/code&gt;). Using &lt;code&gt;std::cmp::max&lt;/code&gt;, we choose the length to be one if the value is &lt;code&gt;value=0&lt;/code&gt; so we print &lt;code&gt;0&lt;/code&gt; (rather than an empty string).&lt;/li&gt;
&lt;li&gt;We then test each bit with &lt;code&gt;0b1 &amp;amp; (value &amp;lt;&amp;lt; i)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;If the result of the bitwise and is zero (no match) then we append the &lt;code&gt;0&lt;/code&gt; character else &lt;code&gt;1&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;to_binary&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; buf &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; start &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;std&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;cmp&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;max&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;BITS&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;leading_zeros&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;start)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; bit_set &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0b1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; i);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; bit_set &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;0&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;1&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    buf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;to_binary&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; buf &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; start &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;std&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;cmp&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;max&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;BITS&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;leading_zeros&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;start)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; bit_set &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0b1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; i);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; bit_set &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;0&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;1&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    buf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;There are a few other ways of doing this, but this seemed the neatest&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Parsing is the reverse of this, we take each character in the string, checking if it is &lt;code&gt;0&lt;/code&gt; and add the result (through bitwise or). Each iteration we shift the accumulator value one bit to the left (equivalent to multiplying by two).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_binary&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Result&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, ()&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; byte &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;bytes&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;0&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;1&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; byte {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (byte &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;1&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Err&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(value)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_binary&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Result&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, ()&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; byte &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;bytes&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;0&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;1&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; byte {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (byte &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;1&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Err&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(value)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;p&gt;Moving on, in the real world we use base 10 or &lt;a href=&quot;https://en.wikipedia.org/wiki/Decimal&quot;&gt;denary&lt;/a&gt;. Likely because most of the population has ten fingers.&lt;/p&gt;
&lt;p&gt;The logic is similar but because 10 is not a power of 2 we use division instead of shifts and modulo instead of bitwise and for testing bits.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;to_denary&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, separator&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;to_owned&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; buf &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;ilog10&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;())&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; j &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;i32&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;pow&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(i) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;quot;0123456789&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[j] &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(separator);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    buf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;to_denary&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, separator&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;to_owned&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; buf &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;ilog10&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;())&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; j &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;i32&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;pow&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(i) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;quot;0123456789&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[j] &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(separator);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    buf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Here this function also takes a separator paramter. This allows formatting &lt;code&gt;123456789&lt;/code&gt; to return in more readable &lt;code&gt;123 456 789&lt;/code&gt; form when &lt;code&gt;separator=&amp;quot; &amp;quot;&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Parsing is similar. Again because 10 is not a power of 2 we use multiplication instead of shifts and addition rather than bitwise ors.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_denary&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Result&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, ()&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; byte &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;bytes&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;0&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;9&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; byte {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(byte &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;b&amp;#39;0&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Err&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(value)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_denary&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Result&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, ()&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; byte &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;bytes&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;0&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;9&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; byte {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(byte &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;b&amp;#39;0&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Err&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(value)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Other radix are also commonly used such as base 8, 16 and 64. These are respectively named octal, hexadecimal and base64 (it needs a better new name).&lt;/p&gt;
&lt;p&gt;These use similar logic to that of binary (as they are powers of 2). Hex has an extended alphabet beyond the 9 character introducing &lt;code&gt;ABCDEF&lt;/code&gt;. Additionally, these formats formatting and parsing logic inspects more than one bit at a time during formatting.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;natural-language&quot; tabindex=&quot;-1&quot;&gt;Natural language&lt;/h3&gt;
&lt;p&gt;Moving past symbols, we can use words to spell out numbers. As we will see it isn’t as simple as printing 135 as one three five.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/diagrams/one-three-five.svg&quot; alt=&quot;135 != one three five&quot; /&gt;&lt;/p&gt;
&lt;p&gt;We have various scales: digits (&lt;code&gt;1&lt;/code&gt;), tens (&lt;code&gt;10&lt;/code&gt;), hundreds (&lt;code&gt;100&lt;/code&gt;) and thousands (&lt;code&gt;1000&lt;/code&gt;). Larger values then break into combinations with tens of thousands (&lt;code&gt;10 000&lt;/code&gt;) and hundreds of thousands (&lt;code&gt;100 000&lt;/code&gt;). When we get to thousands and thousands it starts to become confusing, so we break into a new term: the millions.&lt;/p&gt;
&lt;p&gt;Thousands of millions is billions and millions of thousands of billions is trillions. We notice that millions has a &lt;strong&gt;m&lt;/strong&gt; prefix and for &lt;strong&gt;bi&lt;/strong&gt;llions we are at the 2 prefix that is used from &lt;strong&gt;bi&lt;/strong&gt;nary. Successive quantaties are &lt;strong&gt;tri&lt;/strong&gt;llions, &lt;strong&gt;quad&lt;/strong&gt;rillions.&lt;/p&gt;
&lt;p&gt;In the following, we see that a number formatted to English roughy follows a form where we have a list of triples. A term between 1-999 followed by a magnitude. There is no magnitude for one, so we leave it out.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/diagrams/parts.svg&quot; alt=&quot;parts&quot; /&gt;&lt;/p&gt;
&lt;p&gt;In English we have names for &lt;code&gt;0-10&lt;/code&gt; and additionally &lt;code&gt;11-13&lt;/code&gt;. &lt;code&gt;14-20&lt;/code&gt; is + &amp;quot;teen&amp;quot;. twenty has tw-o prefix. and so on. All &lt;svg style=&quot;vertical-align: -0.05ex;&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;5.757ex&quot; height=&quot;1.557ex&quot; role=&quot;img&quot; focusable=&quot;false&quot; viewBox=&quot;0 -666 2544.4 688&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;defs&gt;&lt;path id=&quot;MJX-3-TEX-N-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-3-TEX-N-30&quot; d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-3-TEX-N-2217&quot; d=&quot;M229 286Q216 420 216 436Q216 454 240 464Q241 464 245 464T251 465Q263 464 273 456T283 436Q283 419 277 356T270 286L328 328Q384 369 389 372T399 375Q412 375 423 365T435 338Q435 325 425 315Q420 312 357 282T289 250L355 219L425 184Q434 175 434 161Q434 146 425 136T401 125Q393 125 383 131T328 171L270 213Q283 79 283 63Q283 53 276 44T250 35Q231 35 224 44T216 63Q216 80 222 143T229 213L171 171Q115 130 110 127Q106 124 100 124Q87 124 76 134T64 161Q64 166 64 169T67 175T72 181T81 188T94 195T113 204T138 215T170 230T210 250L74 315Q65 324 65 338Q65 353 74 363T98 374Q106 374 116 368T171 328L229 286Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-3-TEX-I-1D45B&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;scale(1,-1)&quot;&gt;&lt;g data-mml-node=&quot;math&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;31&quot; xlink:href=&quot;#MJX-3-TEX-N-31&quot;&gt;&lt;/use&gt;&lt;use data-c=&quot;30&quot; xlink:href=&quot;#MJX-3-TEX-N-30&quot; transform=&quot;translate(500,0)&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mo&quot; transform=&quot;translate(1222.2,0)&quot;&gt;&lt;use data-c=&quot;2217&quot; xlink:href=&quot;#MJX-3-TEX-N-2217&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mi&quot; transform=&quot;translate(1944.4,0)&quot;&gt;&lt;use data-c=&quot;1D45B&quot; xlink:href=&quot;#MJX-3-TEX-I-1D45B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt; have names&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;under_100_to_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;one&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;two&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;three&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;four&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;five&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;six&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;7&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;seven&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;eight&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;nine&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;ten&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;11&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;eleven&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;twelve&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;13&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;thirteen&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;14&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;fourteen&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;15&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;fifthteen&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;16&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;sixteen&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;17&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;seventeen&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;18&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;eighteen&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;19&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;nineteen&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;twenty&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;thirty&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;fourty&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;fifty&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;sixty&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;70&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;seventy&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;80&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;eighty&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;90&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;ninety&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    number &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;unreachable!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;{number}&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;under_100_to_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;one&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;two&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;three&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;four&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;five&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;six&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;7&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;seven&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;eight&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;nine&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;ten&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;11&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;eleven&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;twelve&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;13&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;thirteen&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;14&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;fourteen&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;15&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;fifthteen&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;16&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;sixteen&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;17&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;seventeen&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;18&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;eighteen&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;19&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;nineteen&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;twenty&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;thirty&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;fourty&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;fifty&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;sixty&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;70&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;seventy&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;80&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;eighty&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;90&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;ninety&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    number &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;unreachable!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;{number}&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Interestingly, in French 80 is quatre vingts which translates to four twenties (&lt;svg style=&quot;vertical-align: -0.186ex;&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;10.81ex&quot; height=&quot;1.717ex&quot; role=&quot;img&quot; focusable=&quot;false&quot; viewBox=&quot;0 -677 4778 759&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;defs&gt;&lt;path id=&quot;MJX-4-TEX-N-34&quot; d=&quot;M462 0Q444 3 333 3Q217 3 199 0H190V46H221Q241 46 248 46T265 48T279 53T286 61Q287 63 287 115V165H28V211L179 442Q332 674 334 675Q336 677 355 677H373L379 671V211H471V165H379V114Q379 73 379 66T385 54Q393 47 442 46H471V0H462ZM293 211V545L74 212L183 211H293Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-4-TEX-N-2217&quot; d=&quot;M229 286Q216 420 216 436Q216 454 240 464Q241 464 245 464T251 465Q263 464 273 456T283 436Q283 419 277 356T270 286L328 328Q384 369 389 372T399 375Q412 375 423 365T435 338Q435 325 425 315Q420 312 357 282T289 250L355 219L425 184Q434 175 434 161Q434 146 425 136T401 125Q393 125 383 131T328 171L270 213Q283 79 283 63Q283 53 276 44T250 35Q231 35 224 44T216 63Q216 80 222 143T229 213L171 171Q115 130 110 127Q106 124 100 124Q87 124 76 134T64 161Q64 166 64 169T67 175T72 181T81 188T94 195T113 204T138 215T170 230T210 250L74 315Q65 324 65 338Q65 353 74 363T98 374Q106 374 116 368T171 328L229 286Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-4-TEX-N-32&quot; d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-4-TEX-N-30&quot; d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-4-TEX-N-3D&quot; d=&quot;M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-4-TEX-N-38&quot; d=&quot;M70 417T70 494T124 618T248 666Q319 666 374 624T429 515Q429 485 418 459T392 417T361 389T335 371T324 363L338 354Q352 344 366 334T382 323Q457 264 457 174Q457 95 399 37T249 -22Q159 -22 101 29T43 155Q43 263 172 335L154 348Q133 361 127 368Q70 417 70 494ZM286 386L292 390Q298 394 301 396T311 403T323 413T334 425T345 438T355 454T364 471T369 491T371 513Q371 556 342 586T275 624Q268 625 242 625Q201 625 165 599T128 534Q128 511 141 492T167 463T217 431Q224 426 228 424L286 386ZM250 21Q308 21 350 55T392 137Q392 154 387 169T375 194T353 216T330 234T301 253T274 270Q260 279 244 289T218 306L210 311Q204 311 181 294T133 239T107 157Q107 98 150 60T250 21Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;scale(1,-1)&quot;&gt;&lt;g data-mml-node=&quot;math&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;34&quot; xlink:href=&quot;#MJX-4-TEX-N-34&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mo&quot; transform=&quot;translate(722.2,0)&quot;&gt;&lt;use data-c=&quot;2217&quot; xlink:href=&quot;#MJX-4-TEX-N-2217&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mn&quot; transform=&quot;translate(1444.4,0)&quot;&gt;&lt;use data-c=&quot;32&quot; xlink:href=&quot;#MJX-4-TEX-N-32&quot;&gt;&lt;/use&gt;&lt;use data-c=&quot;30&quot; xlink:href=&quot;#MJX-4-TEX-N-30&quot; transform=&quot;translate(500,0)&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mo&quot; transform=&quot;translate(2722.2,0)&quot;&gt;&lt;use data-c=&quot;3D&quot; xlink:href=&quot;#MJX-4-TEX-N-3D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mn&quot; transform=&quot;translate(3778,0)&quot;&gt;&lt;use data-c=&quot;38&quot; xlink:href=&quot;#MJX-4-TEX-N-38&quot;&gt;&lt;/use&gt;&lt;use data-c=&quot;30&quot; xlink:href=&quot;#MJX-4-TEX-N-30&quot; transform=&quot;translate(500,0)&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Now we have an idea about the composition, we can start working on formatting and printing. We split the input into triples with prefixes of 0-999, print this as the prefix and then append a magnitude (thousands, millions etc)&lt;/p&gt;
&lt;p&gt;We have a few conditions for edge cases such as not printing &amp;quot;one million, zero thousand and zero&amp;quot;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;to_english&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;format_part&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(part&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, is_last&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; hundred &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; hundred &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_empty&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;under_100_to_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(hundred));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot; hundred&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_empty&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; is_last &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; hundred &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot; and &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;under_100_to_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(part));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; digit &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; tens &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; digit;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;under_100_to_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(tens));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; digit &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;under_100_to_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(digit));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;PART_WIDTH&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;u32&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;MAGNITUDES&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot; thousand&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot; million&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot; billion&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot; trillion&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot; quadrillion&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot; quintillion&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    ];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;zero&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;to_owned&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; buf &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;ilog10&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;PART_WIDTH&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; size &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;10_&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;pow&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(i &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;PART_WIDTH&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; left &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; size;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; left &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; after &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (left &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; size);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; is_last &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; after &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;format_part&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(part, is_last, &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; buf);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_empty&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;MAGNITUDES&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[i &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    buf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;to_english&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;format_part&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(part&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, is_last&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; hundred &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; hundred &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_empty&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;under_100_to_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(hundred));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot; hundred&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_empty&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; is_last &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;||&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; hundred &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot; and &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;under_100_to_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(part));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; digit &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; tens &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; digit;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;under_100_to_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(tens));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; digit &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;under_100_to_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(digit));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;PART_WIDTH&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;u32&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;MAGNITUDES&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot; thousand&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot; million&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot; billion&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot; trillion&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot; quadrillion&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot; quintillion&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    ];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;zero&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;to_owned&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; buf &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;ilog10&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;PART_WIDTH&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; size &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;10_&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;pow&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(i &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;PART_WIDTH&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; left &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; size;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; left &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; after &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (left &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; size);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; is_last &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; after &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;format_part&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(part, is_last, &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; buf);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_empty&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; part &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;MAGNITUDES&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[i &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    buf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We do similar for parsing, we break the input string into parts (where each part lines up with the triple structure) and do reverse lookup. &lt;a href=&quot;https://github.com/kaleidawave/experiments/blob/daf25161d49dd3700b97d091d7ee2397df19810f/number-utilities/src/parse.rs#L47&quot;&gt;The code is a bit longer so is skipped for this post&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Notenote &lt;code&gt;and&lt;/code&gt; refers to addition and each item prefixes a magnitude (with a lower precedence) which is multipied by the magnitude.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/diagrams/decomposition.svg&quot; alt=&quot;decomposition&quot; /&gt;&lt;/p&gt;
&lt;h3 id=&quot;roman-numerals&quot; tabindex=&quot;-1&quot;&gt;Roman numerals&lt;/h3&gt;
&lt;p&gt;On to the title and raison d&#39;etre for this post. &lt;a href=&quot;https://en.wikipedia.org/wiki/Roman_numerals&quot;&gt;Roman numerals&lt;/a&gt; are an ancient form of denoting amounts.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/other/clocktower.png&quot; alt=&quot;clocktower&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The crop up in analog clock faces, television production dates and enumerating royals with the same forename. The traditional dialect is limited to representing the numbers between 1-3999.&lt;/p&gt;
&lt;p&gt;Their design uses several uppercase characters. &lt;code&gt;I=1&lt;/code&gt; being the smallest, then &lt;code&gt;V=5&lt;/code&gt;, &lt;code&gt;X=10&lt;/code&gt;, &lt;code&gt;L=50&lt;/code&gt;, &lt;code&gt;C=100&lt;/code&gt;, &lt;code&gt;D=500&lt;/code&gt; and finally &lt;code&gt;M=1000&lt;/code&gt;. We see that all &lt;em&gt;digits&lt;/em&gt; take the form of &lt;svg style=&quot;vertical-align: -0.05ex;&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;6.678ex&quot; height=&quot;1.646ex&quot; role=&quot;img&quot; focusable=&quot;false&quot; viewBox=&quot;0 -705.6 2951.7 727.6&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;defs&gt;&lt;path id=&quot;MJX-5-TEX-N-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-5-TEX-N-2217&quot; d=&quot;M229 286Q216 420 216 436Q216 454 240 464Q241 464 245 464T251 465Q263 464 273 456T283 436Q283 419 277 356T270 286L328 328Q384 369 389 372T399 375Q412 375 423 365T435 338Q435 325 425 315Q420 312 357 282T289 250L355 219L425 184Q434 175 434 161Q434 146 425 136T401 125Q393 125 383 131T328 171L270 213Q283 79 283 63Q283 53 276 44T250 35Q231 35 224 44T216 63Q216 80 222 143T229 213L171 171Q115 130 110 127Q106 124 100 124Q87 124 76 134T64 161Q64 166 64 169T67 175T72 181T81 188T94 195T113 204T138 215T170 230T210 250L74 315Q65 324 65 338Q65 353 74 363T98 374Q106 374 116 368T171 328L229 286Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-5-TEX-N-30&quot; d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-5-TEX-I-1D45B&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;scale(1,-1)&quot;&gt;&lt;g data-mml-node=&quot;math&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;31&quot; xlink:href=&quot;#MJX-5-TEX-N-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mo&quot; transform=&quot;translate(722.2,0)&quot;&gt;&lt;use data-c=&quot;2217&quot; xlink:href=&quot;#MJX-5-TEX-N-2217&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;msup&quot; transform=&quot;translate(1444.4,0)&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;31&quot; xlink:href=&quot;#MJX-5-TEX-N-31&quot;&gt;&lt;/use&gt;&lt;use data-c=&quot;30&quot; xlink:href=&quot;#MJX-5-TEX-N-30&quot; transform=&quot;translate(500,0)&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mi&quot; transform=&quot;translate(1033,393.1) scale(0.707)&quot;&gt;&lt;use data-c=&quot;1D45B&quot; xlink:href=&quot;#MJX-5-TEX-I-1D45B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt; or &lt;svg style=&quot;vertical-align: -0.05ex;&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;6.678ex&quot; height=&quot;1.646ex&quot; role=&quot;img&quot; focusable=&quot;false&quot; viewBox=&quot;0 -705.6 2951.7 727.6&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;defs&gt;&lt;path id=&quot;MJX-6-TEX-N-35&quot; d=&quot;M164 157Q164 133 148 117T109 101H102Q148 22 224 22Q294 22 326 82Q345 115 345 210Q345 313 318 349Q292 382 260 382H254Q176 382 136 314Q132 307 129 306T114 304Q97 304 95 310Q93 314 93 485V614Q93 664 98 664Q100 666 102 666Q103 666 123 658T178 642T253 634Q324 634 389 662Q397 666 402 666Q410 666 410 648V635Q328 538 205 538Q174 538 149 544L139 546V374Q158 388 169 396T205 412T256 420Q337 420 393 355T449 201Q449 109 385 44T229 -22Q148 -22 99 32T50 154Q50 178 61 192T84 210T107 214Q132 214 148 197T164 157Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-6-TEX-N-2217&quot; d=&quot;M229 286Q216 420 216 436Q216 454 240 464Q241 464 245 464T251 465Q263 464 273 456T283 436Q283 419 277 356T270 286L328 328Q384 369 389 372T399 375Q412 375 423 365T435 338Q435 325 425 315Q420 312 357 282T289 250L355 219L425 184Q434 175 434 161Q434 146 425 136T401 125Q393 125 383 131T328 171L270 213Q283 79 283 63Q283 53 276 44T250 35Q231 35 224 44T216 63Q216 80 222 143T229 213L171 171Q115 130 110 127Q106 124 100 124Q87 124 76 134T64 161Q64 166 64 169T67 175T72 181T81 188T94 195T113 204T138 215T170 230T210 250L74 315Q65 324 65 338Q65 353 74 363T98 374Q106 374 116 368T171 328L229 286Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-6-TEX-N-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-6-TEX-N-30&quot; d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-6-TEX-I-1D45B&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;scale(1,-1)&quot;&gt;&lt;g data-mml-node=&quot;math&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;35&quot; xlink:href=&quot;#MJX-6-TEX-N-35&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mo&quot; transform=&quot;translate(722.2,0)&quot;&gt;&lt;use data-c=&quot;2217&quot; xlink:href=&quot;#MJX-6-TEX-N-2217&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;msup&quot; transform=&quot;translate(1444.4,0)&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;31&quot; xlink:href=&quot;#MJX-6-TEX-N-31&quot;&gt;&lt;/use&gt;&lt;use data-c=&quot;30&quot; xlink:href=&quot;#MJX-6-TEX-N-30&quot; transform=&quot;translate(500,0)&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mi&quot; transform=&quot;translate(1033,393.1) scale(0.707)&quot;&gt;&lt;use data-c=&quot;1D45B&quot; xlink:href=&quot;#MJX-6-TEX-I-1D45B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;.&lt;/p&gt;
&lt;p&gt;Similar to the above systems we sum each part, so &lt;code&gt;DLV&lt;/code&gt; is &lt;code&gt;500 + 50 + 5 = 555&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;However&lt;/strong&gt;, we can prefix digits to make them smaller. We refer to 9 as &lt;code&gt;IX&lt;/code&gt; and 14 as &lt;code&gt;XIV&lt;/code&gt;. The prefix can only precede digits up to then next &lt;svg style=&quot;vertical-align: -0.05ex;&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;3.41ex&quot; height=&quot;1.646ex&quot; role=&quot;img&quot; focusable=&quot;false&quot; viewBox=&quot;0 -705.6 1507.3 727.6&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;defs&gt;&lt;path id=&quot;MJX-7-TEX-N-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-7-TEX-N-30&quot; d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-7-TEX-I-1D45B&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;scale(1,-1)&quot;&gt;&lt;g data-mml-node=&quot;math&quot;&gt;&lt;g data-mml-node=&quot;msup&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;31&quot; xlink:href=&quot;#MJX-7-TEX-N-31&quot;&gt;&lt;/use&gt;&lt;use data-c=&quot;30&quot; xlink:href=&quot;#MJX-7-TEX-N-30&quot; transform=&quot;translate(500,0)&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mi&quot; transform=&quot;translate(1033,393.1) scale(0.707)&quot;&gt;&lt;use data-c=&quot;1D45B&quot; xlink:href=&quot;#MJX-7-TEX-I-1D45B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt; so 99 is &lt;code&gt;XCIX&lt;/code&gt; (&lt;code&gt;XC + IX = 90 + 9&lt;/code&gt;) and not &lt;code&gt;IC&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Formatting is similar to denary. Then the logic picks a certain sequence for each character&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;to_roman_numeral&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; buf &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assert!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4000&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;cannot format after 3999&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;PARTS&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)] &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;        // (&amp;quot;III&amp;quot;, &amp;quot;IIII&amp;quot;, &amp;quot;VIII&amp;quot;, &amp;quot;IX&amp;quot;), if clock&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;III&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;IV&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;VIII&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;IX&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;XXX&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;XL&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;LXXX&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;XC&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;CCC&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;CD&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;DCCC&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;CM&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;MMM&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    ];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;ilog10&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;())&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; digit &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;10_&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;pow&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(i)) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (zero_to_three, four, five_to_eight, nine) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;PARTS&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[i &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; digit {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;zero_to_three[&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;digit],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; four,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;five_to_eight[&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;digit &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; nine,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;unreachable!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;{value}&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(value);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    buf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;to_roman_numeral&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; buf &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assert!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4000&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;cannot format after 3999&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;PARTS&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)] &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;        // (&amp;quot;III&amp;quot;, &amp;quot;IIII&amp;quot;, &amp;quot;VIII&amp;quot;, &amp;quot;IX&amp;quot;), if clock&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;III&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;IV&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;VIII&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;IX&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;XXX&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;XL&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;LXXX&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;XC&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;CCC&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;CD&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;DCCC&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;CM&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;MMM&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    ];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;ilog10&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;())&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; digit &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;10_&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;pow&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(i)) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (zero_to_three, four, five_to_eight, nine) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;PARTS&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[i &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; digit {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;zero_to_three[&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;digit],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; four,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;five_to_eight[&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;digit &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; nine,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;unreachable!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;{value}&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(value);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    buf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;p&gt;Now we can &lt;em&gt;generate&lt;/em&gt; them, we can perform the inverse and parse them.&lt;/p&gt;
&lt;p&gt;When parsing a roman numeral, we first turn each &lt;svg style=&quot;vertical-align: -0.05ex;&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;6.678ex&quot; height=&quot;1.646ex&quot; role=&quot;img&quot; focusable=&quot;false&quot; viewBox=&quot;0 -705.6 2951.7 727.6&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;defs&gt;&lt;path id=&quot;MJX-8-TEX-N-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-8-TEX-N-2217&quot; d=&quot;M229 286Q216 420 216 436Q216 454 240 464Q241 464 245 464T251 465Q263 464 273 456T283 436Q283 419 277 356T270 286L328 328Q384 369 389 372T399 375Q412 375 423 365T435 338Q435 325 425 315Q420 312 357 282T289 250L355 219L425 184Q434 175 434 161Q434 146 425 136T401 125Q393 125 383 131T328 171L270 213Q283 79 283 63Q283 53 276 44T250 35Q231 35 224 44T216 63Q216 80 222 143T229 213L171 171Q115 130 110 127Q106 124 100 124Q87 124 76 134T64 161Q64 166 64 169T67 175T72 181T81 188T94 195T113 204T138 215T170 230T210 250L74 315Q65 324 65 338Q65 353 74 363T98 374Q106 374 116 368T171 328L229 286Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-8-TEX-N-30&quot; d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-8-TEX-I-1D45B&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;scale(1,-1)&quot;&gt;&lt;g data-mml-node=&quot;math&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;31&quot; xlink:href=&quot;#MJX-8-TEX-N-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mo&quot; transform=&quot;translate(722.2,0)&quot;&gt;&lt;use data-c=&quot;2217&quot; xlink:href=&quot;#MJX-8-TEX-N-2217&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;msup&quot; transform=&quot;translate(1444.4,0)&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;31&quot; xlink:href=&quot;#MJX-8-TEX-N-31&quot;&gt;&lt;/use&gt;&lt;use data-c=&quot;30&quot; xlink:href=&quot;#MJX-8-TEX-N-30&quot; transform=&quot;translate(500,0)&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mi&quot; transform=&quot;translate(1033,393.1) scale(0.707)&quot;&gt;&lt;use data-c=&quot;1D45B&quot; xlink:href=&quot;#MJX-8-TEX-I-1D45B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt; and &lt;svg style=&quot;vertical-align: -0.05ex;&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;6.678ex&quot; height=&quot;1.646ex&quot; role=&quot;img&quot; focusable=&quot;false&quot; viewBox=&quot;0 -705.6 2951.7 727.6&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;defs&gt;&lt;path id=&quot;MJX-9-TEX-N-35&quot; d=&quot;M164 157Q164 133 148 117T109 101H102Q148 22 224 22Q294 22 326 82Q345 115 345 210Q345 313 318 349Q292 382 260 382H254Q176 382 136 314Q132 307 129 306T114 304Q97 304 95 310Q93 314 93 485V614Q93 664 98 664Q100 666 102 666Q103 666 123 658T178 642T253 634Q324 634 389 662Q397 666 402 666Q410 666 410 648V635Q328 538 205 538Q174 538 149 544L139 546V374Q158 388 169 396T205 412T256 420Q337 420 393 355T449 201Q449 109 385 44T229 -22Q148 -22 99 32T50 154Q50 178 61 192T84 210T107 214Q132 214 148 197T164 157Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-9-TEX-N-2217&quot; d=&quot;M229 286Q216 420 216 436Q216 454 240 464Q241 464 245 464T251 465Q263 464 273 456T283 436Q283 419 277 356T270 286L328 328Q384 369 389 372T399 375Q412 375 423 365T435 338Q435 325 425 315Q420 312 357 282T289 250L355 219L425 184Q434 175 434 161Q434 146 425 136T401 125Q393 125 383 131T328 171L270 213Q283 79 283 63Q283 53 276 44T250 35Q231 35 224 44T216 63Q216 80 222 143T229 213L171 171Q115 130 110 127Q106 124 100 124Q87 124 76 134T64 161Q64 166 64 169T67 175T72 181T81 188T94 195T113 204T138 215T170 230T210 250L74 315Q65 324 65 338Q65 353 74 363T98 374Q106 374 116 368T171 328L229 286Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-9-TEX-N-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-9-TEX-N-30&quot; d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-9-TEX-I-1D45B&quot; d=&quot;M21 287Q22 293 24 303T36 341T56 388T89 425T135 442Q171 442 195 424T225 390T231 369Q231 367 232 367L243 378Q304 442 382 442Q436 442 469 415T503 336T465 179T427 52Q427 26 444 26Q450 26 453 27Q482 32 505 65T540 145Q542 153 560 153Q580 153 580 145Q580 144 576 130Q568 101 554 73T508 17T439 -10Q392 -10 371 17T350 73Q350 92 386 193T423 345Q423 404 379 404H374Q288 404 229 303L222 291L189 157Q156 26 151 16Q138 -11 108 -11Q95 -11 87 -5T76 7T74 17Q74 30 112 180T152 343Q153 348 153 366Q153 405 129 405Q91 405 66 305Q60 285 60 284Q58 278 41 278H27Q21 284 21 287Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;scale(1,-1)&quot;&gt;&lt;g data-mml-node=&quot;math&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;35&quot; xlink:href=&quot;#MJX-9-TEX-N-35&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mo&quot; transform=&quot;translate(722.2,0)&quot;&gt;&lt;use data-c=&quot;2217&quot; xlink:href=&quot;#MJX-9-TEX-N-2217&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;msup&quot; transform=&quot;translate(1444.4,0)&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;31&quot; xlink:href=&quot;#MJX-9-TEX-N-31&quot;&gt;&lt;/use&gt;&lt;use data-c=&quot;30&quot; xlink:href=&quot;#MJX-9-TEX-N-30&quot; transform=&quot;translate(500,0)&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mi&quot; transform=&quot;translate(1033,393.1) scale(0.707)&quot;&gt;&lt;use data-c=&quot;1D45B&quot; xlink:href=&quot;#MJX-9-TEX-I-1D45B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt; item into its respective character and then process each &lt;code&gt;letter&lt;/code&gt; in the sequence either by&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Incrementing the accumulator by some amount&lt;/li&gt;
&lt;li&gt;Decrement some future (larger) letter&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot;center&quot;&gt;&lt;p&gt;And here is where the neat two line of code snippet I landed on comes in&lt;/p&gt;
&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;acc &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; letter;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;acc &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (acc &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; letter);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;acc &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; letter;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;acc &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (acc &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; letter);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We increment the value as standard, then if the letter leaves a &lt;em&gt;remainder&lt;/em&gt; with &lt;code&gt;acc&lt;/code&gt; we subtract two of the &lt;em&gt;remainder&lt;/em&gt; from the accumular.&lt;/p&gt;
&lt;p&gt;For example for &lt;code&gt;IX&lt;/code&gt;, after then &lt;code&gt;I&lt;/code&gt; we are left with &lt;code&gt;1&lt;/code&gt; in the accumulator. We add the value of &lt;code&gt;X&lt;/code&gt;, leaving &lt;code&gt;11&lt;/code&gt; in the accumulator. We then find &lt;code&gt;11 % 10&lt;/code&gt; is &lt;code&gt;1&lt;/code&gt;. We subtract &lt;code&gt;2 * 1&lt;/code&gt; from &lt;code&gt;11&lt;/code&gt; arriving at &lt;code&gt;9&lt;/code&gt;!&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This isn&#39;t a true a roman numeral parsing, it supports a superset. It does not check that only one prefix is allowed and the prefix needs to be one less order of ten than the rest. This allows non-unique identifiers as &lt;code&gt;./parse-number IIX --roman&lt;/code&gt; and &lt;code&gt;./parse-number VIII --roman&lt;/code&gt; both return &lt;code&gt;8&lt;/code&gt;. A future improvement would be to add more logic to enforce the rule if required.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;try-it-out&quot; tabindex=&quot;-1&quot;&gt;Try it out&lt;/h3&gt;
&lt;h3 class=&quot;center&quot;&gt;&lt;p&gt;&lt;a href=&quot;https://buy.polar.sh/polar_cl_kzjvIbQBgDJSsD6hLDpMxnsXUxQvtTWP4UUzv300liA&quot;&gt;You can download the command line binaries: parse-number and format-number to try it out for yourself&lt;/a&gt;.&lt;/p&gt;
&lt;/h3&gt;
&lt;h3 id=&quot;testing-and-benchmarking-(bonus)&quot; tabindex=&quot;-1&quot;&gt;Testing and benchmarking (Bonus)&lt;/h3&gt;
&lt;p&gt;Now we have our library we want to make sure that the logic is not complete baloney.&lt;/p&gt;
&lt;p&gt;We will employ some techniques that a contributor showed me when &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/3&quot;&gt;adding fuzzing to one of my projects&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The first is the concept of a round trip. As formatting and parsing are inverse operations, we can tests that &lt;code&gt;number = parse(format(number))&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;As Roman numerals are limited to representing the 1-4000 &lt;a href=&quot;https://github.com/kaleidawave/experiments/blob/daf25161d49dd3700b97d091d7ee2397df19810f/number-utilities/tests/roman_numerals.rs#L5&quot;&gt;we can just test them individually&lt;/a&gt;. We also have to test that it doesn&#39;t just print and parse &lt;code&gt;zero&lt;/code&gt; each time &lt;a href=&quot;https://github.com/kaleidawave/experiments/blob/daf25161d49dd3700b97d091d7ee2397df19810f/number-utilities/tests/roman_numerals.rs#L14&quot;&gt;so we will add a few unit tests as well&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;However, for other formats we want to test a much larger range. While we could test &lt;code&gt;for i in 0..=4_000_000_000&lt;/code&gt; this takes a lot of compute and slows down our testing cycle (especially if we are test each representation). Instead, we will take a large sample of numbers by picking random numbers in this range.&lt;/p&gt;
&lt;p&gt;We do not require the results to be secure so we will use the &lt;code&gt;Mulberry32&lt;/code&gt; generator with an initial seed by the system time and we will run the generator one hundred thousand times.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; elapsed &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;SystemTime&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;now&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;duration_since&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;SystemTime&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;UNIX_EPOCH&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;unwrap&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (elapsed&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;as_micros&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;u32&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; random &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Mulberry32&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { seed&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; _ &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;100_000&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; random_value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; random&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;next_value&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; pow&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;u32&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;10_&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;u32&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;pow&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;((random_value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;rotate_left&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;16&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (random_value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; pow) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value_english &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;to_english&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(value);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; out_value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_english&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;value_english)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;unwrap&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assert_eq!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(value, out_value, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;{value_english} parsed as {out_value}&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; elapsed &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;SystemTime&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;now&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;duration_since&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;SystemTime&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;UNIX_EPOCH&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;unwrap&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (elapsed&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;as_micros&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;u32&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; random &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Mulberry32&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { seed&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; _ &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;100_000&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; random_value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; random&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;next_value&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; pow&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;u32&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;10_&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;u32&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;pow&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;((random_value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;rotate_left&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;16&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (random_value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; pow) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value_english &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;to_english&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(value);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; out_value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_english&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;value_english)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;unwrap&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assert_eq!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(value, out_value, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;{value_english} parsed as {out_value}&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;We also randomise the magnitude of the values, because with ranges in the billions it is a one in a million that we get a number &amp;lt;1000 and we want a few of those to be tested in the parse to make sure parsing with a single part works.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/experiments/blob/daf25161d49dd3700b97d091d7ee2397df19810f/number-utilities/tests/english.rs#L1-L38&quot;&gt;See the full testing here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;benchmarking&quot; tabindex=&quot;-1&quot;&gt;Benchmarking&lt;/h4&gt;
&lt;p&gt;This random sample also gives a good dataset of values to time the checker on. &lt;a href=&quot;https://github.com/kaleidawave/experiments/blob/number-utilities/number-utilities/examples/benchmark.rs&quot;&gt;Splitting the logic for testing English values up and wrapping each with &lt;code&gt;std::time::Instant::now&lt;/code&gt; and &lt;code&gt;elapsed()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&quot;https://github.com/kaleidawave/experiments/actions/runs/16966393754/job/48091590819#step:4:12&quot;&gt;we can see that for &lt;code&gt;100 000&lt;/code&gt; numbers&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;format 37.444574ms. parse 89.915595ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;format 37.444574ms. parse 89.915595ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;In the future we could in benchmark different bases and experiment with SIMD for parsing values&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;conclusion&quot; tabindex=&quot;-1&quot;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Hopefully this was an interesting post covering number representations and logic for formatting and parsing them.&lt;/p&gt;
&lt;p&gt;You can use the functions in your projects &lt;a href=&quot;https://crates.io/crates/number-utilities&quot;&gt;through the crate on crates.io here&lt;/a&gt; and &lt;a href=&quot;https://github.com/kaleidawave/experiments/tree/number-utilities&quot;&gt;you can view more of the code in its (temporary) home here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;More blog posts to come. I wrote down outlines for 25 blog posts last week then wrote this (#XXVI) instead lol&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Ezno 2025</title>
    <link href="https://kaleidawave.github.io/posts/ezno-25/"/>
    <updated>2025-07-03T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/ezno-25/</id>
    <summary>An update on the project</summary>
    <content xml:lang="en" type="html">&lt;p&gt;It has been over 6 months since the last post and after a break I have a &lt;em&gt;little&lt;/em&gt; bit of time again to work on my &lt;a href=&quot;https://github.com/kaleidawave/ezno&quot;&gt;type checker and compiler project&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;Firstly some random achievements from last year (2024) that I have not got around to sharing yet.&lt;/p&gt;
&lt;h2 id=&quot;not-so-recent-achievements&quot; tabindex=&quot;-1&quot;&gt;Not-so-recent achievements&lt;/h2&gt;
&lt;h3 id=&quot;adding-narrowing&quot; tabindex=&quot;-1&quot;&gt;Adding narrowing&lt;/h3&gt;
&lt;p&gt;Narrowing is the modification of the &amp;quot;backing&amp;quot; type of parameters and variables based on runtime expressions. It is now implemented in the checker.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=9g8o3s&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/narrowing-01.png&quot; alt=&quot;narrowing from playground&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This marks &lt;strong&gt;the last big feature&lt;/strong&gt; of the TypeScript type system to be implemented. Remaining blockers in the type checker are either related to synthesis across modules, async and generator code and the finishing of my other crazy type system experiments.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;If there is interest I may do a dedicated post on the process of &lt;em&gt;implementing type narrowing&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;support-for-proxy&quot; tabindex=&quot;-1&quot;&gt;Support for &lt;code&gt;Proxy&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;My arch-nemesis in the JavaScript language, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy&quot;&gt;&lt;code&gt;Proxy&lt;/code&gt; is a special object&lt;/a&gt; that can have custom behaviour when used. Basic partial application and &lt;em&gt;some&lt;/em&gt; subtyping checks (&lt;em&gt;but not all&lt;/em&gt;) are implemented in the checker.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=8w9hc8&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/proxy-01.png&quot; alt=&quot;proxy in playgound&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Additionally thanks to a PR, &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/specification/specification.md#regular-expressions&quot;&gt;support for &lt;code&gt;RegExp&lt;/code&gt;s also works&lt;/a&gt;. At some point I write a blog summarising how custom objects such as &lt;code&gt;Proxy&lt;/code&gt; and &lt;code&gt;RegExp&lt;/code&gt; work in the checker.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;tree-shaking&quot; tabindex=&quot;-1&quot;&gt;Tree-shaking&lt;/h3&gt;
&lt;p&gt;While the parser and type-checker make up most of the code in the project, there are other tools that use the generated AST and type checking information. Thanks to behavior in the checker, it does not become too difficult to add tree-shaking to the output. Because of support for the &lt;code&gt;Proxy&lt;/code&gt; above, the following becomes possible.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/506be8be8b6f1de2423ecab6413b31e3cb0ce58c/src/build.rs#L185&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/tree-shaking-01.png&quot; alt=&quot;command output&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;While this is based on results from the type checker, it is not the actual types that enable this behaviour.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;new-lexer-design&quot; tabindex=&quot;-1&quot;&gt;New &lt;em&gt;lexer&lt;/em&gt; design&lt;/h3&gt;
&lt;p&gt;A parser turns strings into a tree-like data structure representing the program. Typically this is done by first &amp;quot;tokenising&amp;quot; the input string and then passing that off to a &lt;em&gt;recursive-descent-parser&lt;/em&gt; to construct the data structure.&lt;/p&gt;
&lt;p&gt;Previously I got a bit carried away with an over-engineered design that produced tokens in one thread and read them in a second. This had lots of problems with edge case syntax where &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/199&quot;&gt;the lexer required information from the higher level parsing&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In an on-going effort to take learnings to make the project simpler, I removed this system in terms of a more basic implementation wrapper &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/506be8be8b6f1de2423ecab6413b31e3cb0ce58c/parser/src/lexer.rs#L122&quot;&gt;for a string reader&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;...and often simplification leads to improved performance.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://x.com/kaleidawave/status/1846238071026487560&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/new-parser-design.jpg&quot; alt=&quot;change in diagnostics&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;this has been merged but is not yet released under the &lt;a href=&quot;https://crates.io/crates/ezno-parser&quot;&gt;parser crate&lt;/a&gt; at the time of writing&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;more-on-the-parser&quot; tabindex=&quot;-1&quot;&gt;More on the parser&lt;/h3&gt;
&lt;p&gt;On the topic of the parser I have been experimenting with more features including&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/parser/generator/tests/structures.rs&quot;&gt;A compile time macro for AST generation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/tree/main/parser/visitable-derive&quot;&gt;Implementing a visitor pattern using derive macros&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/parser/examples/pretty_printing.rs&quot;&gt;&lt;em&gt;Pretty&lt;/em&gt; formatting&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;...and &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/parser/tests/partial.rs&quot;&gt;partial syntax&lt;/a&gt;, which enables the checker to still function while editing the source.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=95mlmo&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/partial-syntax-01.png&quot; alt=&quot;partial syntax at work&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In the future there should be variable name suggestions at the cursor&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Again if there is interest I may do a dedicated blog post on the whole of the parser&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;immediately-next-up&quot; tabindex=&quot;-1&quot;&gt;Immediately next up&lt;/h2&gt;
&lt;p&gt;Here are some things I have started but have not completed yet&lt;/p&gt;
&lt;h3 id=&quot;updating-the-specification&quot; tabindex=&quot;-1&quot;&gt;Updating the specification&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/specification/specification.md&quot;&gt;&amp;quot;The specification&amp;quot; is a markdown document that contains a bunch of tests for type-checking behavior&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This document is invaluable for describing the state of the project as avoiding regressions with changes to the codebase.&lt;/p&gt;
&lt;p&gt;However, I am not satisfied with the current state. &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/230&quot;&gt;So I have started to work on updating it&lt;/a&gt;. The updates are as follows&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/tree/specification-two/specification/02-checker&quot;&gt;Splitting the 5k LOC file into multiple files&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/specification-two/specification/02-checker/01-types/03-generics/01-inference-and-substitution.md#implementation&quot;&gt;Adding additional implementation information to sections&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/experiments/pull/2&quot;&gt;Moving the implementation to its own CLI tool&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;Again I may write a blog post on my approach to testing the checker and some ideas I have for this tool!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;add-a-flag-to-disable-the-events-and-partial-application-system&quot; tabindex=&quot;-1&quot;&gt;Add a flag to disable the events and partial application system&lt;/h3&gt;
&lt;p&gt;The events system is a unique part of the type checker and has major consequences for checking behavior.&lt;/p&gt;
&lt;p&gt;While it has solved some of the hard problems I have wanted to solve with this checker, it is unfortuantly quite complex and current falls short to be effective in real world projects.&lt;/p&gt;
&lt;p&gt;Because the system does not currently work in many scenarios, it is holding back the other type checker features from being used.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/15ef12e1a640d27e52cdf6314bcd4447c3023eab/src/cli.rs#L124-L126&quot;&gt;So last year I started on moving the system behing a flag&lt;/a&gt;. With some more testing a opt in &lt;code&gt;--basic&lt;/code&gt; flag would disable events on the project and the checker would use a simpler variable and object system that is more on par with TypeScript.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I have been wanting to do a blog post on the state of this partial implemented partial application feature but I think for now it would better as a talk. If you run a meetup and interested in this &lt;a href=&quot;https://twitter.com/kaleidawave&quot;&gt;then get in contact&lt;/a&gt;!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;finish-the-inference-addition&quot; tabindex=&quot;-1&quot;&gt;Finish the inference addition&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/197&quot;&gt;Last year I had spent some time on adding a constraint inference implementation&lt;/a&gt;. &lt;a href=&quot;https://hegel.js.org/docs/type-inference#arguments&quot;&gt;A feature that the Hegel type checker had&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/constraint-inference/checker/specification/staging.md&quot;&gt;I have a few things working&lt;/a&gt; but there is still more to do. It would also be good to work with some real world untyped code in parralel with specific cases.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I ended up binning the original implementation (&lt;a href=&quot;https://kaleidawave.github.io/posts/introducing-ezno/#untyped-parameters&quot;&gt;from the announcement&lt;/a&gt;) as it did a lot of mutation that breaks thing in conditional branches and elsewhere. The newer implementation is now to &lt;em&gt;collect requirements&lt;/em&gt; at the end of scope, rather than modifying the type of parameters as the parameter is being used.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;add-test262-checking&quot; tabindex=&quot;-1&quot;&gt;Add test262 checking&lt;/h3&gt;
&lt;p&gt;For JavaScript there exists a test suite of JavaScript code. It is mainly designed for engines that evaluate the code. But we can use the over 50 000 tests cases for the parser in this project.&lt;/p&gt;
&lt;p&gt;On my WIP branch, the parser &lt;a href=&quot;https://github.com/kaleidawave/ezno/actions/runs/16058235661/job/45317842768#step:3:373&quot;&gt;passes 91.8% of these&lt;/a&gt;. I should note that of the 4111 &lt;em&gt;failing&lt;/em&gt; tests, 2395 are &amp;quot;parsed when should have failed&amp;quot;. They could be duplicate parameter names, regular expressions or others. The first two are implemented at the type checker level, but could be up the chain under a flag. Now that this statistic is tracked it should only go upwards!&lt;/p&gt;
&lt;p&gt;While the current tests only run parsing, the type checker could also be run on the files. This could uncover any crashes or places where it might not terminate. Some of these tests could also be used to test the partial application system!&lt;/p&gt;
&lt;h3 id=&quot;an-api-for-the-type-system&quot; tabindex=&quot;-1&quot;&gt;An API for the type system&lt;/h3&gt;
&lt;p&gt;I think the most developed part of this project is the subtyping and disjoint code. &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/15ef12e1a640d27e52cdf6314bcd4447c3023eab/checker/examples/calculate_subtypes.rs&quot;&gt;You can see an example of how it is used here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As that functionality is pretty much ready, it could be exposed to other project through an API.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; space &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Space&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assert!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(space&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_assignable_to&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;number | string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assert!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;space&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_assignable_to&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;number | string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; space &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Space&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assert!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(space&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_assignable_to&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;number | string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assert!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;space&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_assignable_to&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;number | string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you are interested in using subtype logic, you can &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/232&quot;&gt;leave feedback for developing an API for it here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;future&quot; tabindex=&quot;-1&quot;&gt;Future&lt;/h2&gt;
&lt;p&gt;Other ideas that are on backburner&lt;/p&gt;
&lt;h3 id=&quot;continue-on-improving-performance-and-architecture&quot; tabindex=&quot;-1&quot;&gt;Continue on improving performance and architecture&lt;/h3&gt;
&lt;p&gt;While the tool is fast enough, it is a personal endeavour to learn new ways to make it even faster.&lt;/p&gt;
&lt;p&gt;I have been working on a few things&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Investigating the size of types. &lt;a href=&quot;https://github.com/kaleidawave/experiments/pull/10&quot;&gt;I have created a parser for type size information from the Rust compiler&lt;/a&gt; and the hope is to add some more analysis to the output to aid in the changes needed to shrink certain enums.&lt;/li&gt;
&lt;li&gt;Performance mainly comes from structure of the data and large rewrites can be cumbersome. I have given some transformation tools a spin but I have found them too general, so &lt;a href=&quot;https://github.com/kaleidawave/experiments/pull/9&quot;&gt;I am building my own tool using tree-sitter&lt;/a&gt;. The hope is that it can make changes to enum and struct definitions and change corresponding usage in the parsing, to-string, checking and transformation functions.&lt;/li&gt;
&lt;li&gt;To see whether changes have some effect I have been building on GitHub actions to track changes and run benchmarks. &lt;a href=&quot;https://github.com/kaleidawave/ezno/actions/runs/16058398083&quot;&gt;This includes comparing existing binaries as well as memory and CPU instructions tracking&lt;/a&gt;, which gives an accurate picture of performance changes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;more-complete-ness%3A-async%2C-promises%2C-reading-.d.ts-files-etc-and-focus-more-on-examples&quot; tabindex=&quot;-1&quot;&gt;More complete-ness: &lt;code&gt;async&lt;/code&gt;, &lt;code&gt;Promise&lt;/code&gt;s, reading &lt;code&gt;.d.ts&lt;/code&gt; files etc and focus more on examples&lt;/h3&gt;
&lt;p&gt;Now that narrowing has been finished, the last parts of checking are &lt;code&gt;async&lt;/code&gt; code, generators and the whole module system.&lt;/p&gt;
&lt;p&gt;I have been pushing back some of these later features for a while. With a mode that disables the events system, it could become alot easier to get basic support working for these final items.&lt;/p&gt;
&lt;h3 id=&quot;releasing-syntax-ideas-(under-flags)&quot; tabindex=&quot;-1&quot;&gt;Releasing syntax ideas (under flags)&lt;/h3&gt;
&lt;p&gt;I have had some ideas for syntax extensions. They have been sitting in my &lt;em&gt;private experiments folder&lt;/em&gt; but maybe it is worth posting them, less as a feature to go out and use but as some interesting ideas of what can be done with types!&lt;/p&gt;
&lt;h2 id=&quot;other-information&quot; tabindex=&quot;-1&quot;&gt;Other information&lt;/h2&gt;
&lt;p&gt;Soon I will be even more available, I am looking for short-term/internship opportunities!&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I have experience with: Rust, parsers/compilers, things that involve &amp;quot;types&amp;quot; and web (frontend/backend)&lt;/li&gt;
&lt;li&gt;Random other current interests: natural language processing, &lt;em&gt;internal tooling&lt;/em&gt;, databases and &lt;em&gt;video&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And again if there is a place that would be good to host a talk on the progress on the events system (or any other Rust and TypeScript stuff)! &lt;a href=&quot;https://kaleidawave.github.io/about&quot;&gt;You can contact me here&lt;/a&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Thanks for reading the update! and all going well, more features soon!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Mapped types</title>
    <link href="https://kaleidawave.github.io/posts/mapped-types/"/>
    <updated>2024-11-27T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/mapped-types/</id>
    <summary>Implementing mapped types</summary>
    <content xml:lang="en" type="html">&lt;p&gt;At the start of this year, I started implementing checking for &lt;a href=&quot;https://www.typescriptlang.org/docs/handbook/2/mapped-types.html&quot;&gt;TypeScript&#39;s mapped type feature&lt;/a&gt;. I always had it in the back of my mind that this would be some of the hardest logic in TSC to re-implement. While I could have just skipped types using this mapped feature and treated them as &lt;code&gt;any&lt;/code&gt;, I instead thought that having worked on some more realistic subtype and typed things, it would be an interesting challenge to get this complicated system verified by the Ezno type checker.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;For those who haven&#39;t heard of it before, the &lt;a href=&quot;https://github.com/kaleidawave/ezno&quot;&gt;Ezno&lt;/a&gt; type checker is a work-in-progress but fast and correct TypeScript type checker and compiler with additional experiments.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This post covers what mapped types are, a deep dive on generic checking and representing object types and finishes up covering some advanced property features that the type checker covers. You can read see an &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/specification/specification.md#mapped-types&quot;&gt;overview the additions in the specification&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The Ezno type checker is built from the ground up. &amp;quot;Implementing&amp;quot; means getting &lt;em&gt;mostly&lt;/em&gt; the same behaviour/output. No code or logic is copied from TSC. This post covers my approach to implementing mapped types, which may be different (or the same) as the TSC implementation. &lt;a href=&quot;https://kaleidawave.github.io/ezno/comparison/&quot;&gt;Infact there are many different behaviors in Ezno compared to TSC&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Much like many of the things in checker, there are still edge cases and a few other things that don&#39;t quite work at the moment. If you find them, then feel free to &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/new&quot;&gt;raise an issue&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-basics-of-object-properties&quot; tabindex=&quot;-1&quot;&gt;The basics of object properties&lt;/h2&gt;
&lt;p&gt;In TypeScript, we can define objects with &lt;em&gt;fixed&lt;/em&gt; keys&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Event&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Date&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;date&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;/* ... */&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;renderEvent&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Event&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`/events/${&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;identifer&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;formattedDate&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(event.name);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`&amp;lt;a href=&amp;quot;${&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;}&amp;quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;		${&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;} @ ${&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;formattedDate&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;	&amp;lt;/a&amp;gt;`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Event&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Date&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;date&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;/* ... */&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;renderEvent&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Event&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`/events/${&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;identifer&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;formattedDate&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(event.name);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`&amp;lt;a href=&amp;quot;${&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;}&amp;quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;		${&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;} @ ${&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;formattedDate&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;	&amp;lt;/a&amp;gt;`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we define a &lt;code&gt;Event&lt;/code&gt; type with an object. We represent properties as a list of key-value pair tuples.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;properties &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;id&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;date&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;properties &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;id&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;date&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;This representation of events is greatly simplified for now but will be built on later.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;There are several parts of the &lt;code&gt;renderEvent&lt;/code&gt; function where we have to inspect the properties of &lt;code&gt;Event&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;First we see &lt;code&gt;event.identifer&lt;/code&gt;. With this access expression we want to attempt to get the value associated with the &lt;code&gt;&amp;quot;identifier&amp;quot;&lt;/code&gt; property key from the property list above. Finding the associate property value is quite straightforward to do in Rust using iterators.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; want_key &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;identifier&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; properties&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find_map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(key, value)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		(key &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; want_key)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;then_some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(value)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; want_key &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;identifier&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; properties&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find_map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(key, value)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		(key &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; want_key)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;then_some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(value)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, when we run the above, we do not find any property pair whose key (the first item in the pair) is &lt;code&gt;&amp;quot;identifier&amp;quot;&lt;/code&gt;. From this we raise a type error.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;We also return &lt;code&gt;any&lt;/code&gt; here, &lt;a href=&quot;https://kaleidawave.github.io/posts/sets-types-and-type-checking/#short-circuiting-and-continuing-on-errors&quot;&gt;so we can continue type checking&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Later on in the function we see &lt;code&gt;event.name&lt;/code&gt; passed as an argument to &lt;code&gt;formatDate&lt;/code&gt;. Again we run our search and this time it finds a key &lt;code&gt;== &amp;quot;time&amp;quot;&lt;/code&gt;. The RHS value in this pair is the &lt;code&gt;string&lt;/code&gt; type. As it used as argument we check it against the &lt;code&gt;date: Date&lt;/code&gt; parameter of &lt;code&gt;formatDate&lt;/code&gt; and therefore find another error as we cannot assign &lt;code&gt;string&lt;/code&gt; to &lt;code&gt;Date&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=32i0aq&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/basic-property-lookup-and-checking.png&quot; alt=&quot;basic-property-lookup-and-checking&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Raising these type errors hints the programmer at how to correct the code. In this fixed version we can correct the access to use an actual property.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;renderEvent&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Event&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`/events/${&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;formattedDate&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(event.time);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`&amp;lt;a href=&amp;quot;${&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;}&amp;quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;		${&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;} @ ${&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;formattedDate&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;	&amp;lt;/a&amp;gt;`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;renderEvent&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Event&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`/events/${&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;formattedDate&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(event.time);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`&amp;lt;a href=&amp;quot;${&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;}&amp;quot;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;		${&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;event&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;} @ ${&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;formattedDate&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;	&amp;lt;/a&amp;gt;`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;more-advanced-shapes-of-objects&quot; tabindex=&quot;-1&quot;&gt;More advanced shapes of objects&lt;/h3&gt;
&lt;p&gt;This first example is relatively simple. However, keys can get more complex than this. For example the &lt;code&gt;Array&lt;/code&gt; type has the &lt;code&gt;number&lt;/code&gt; type as a property key.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	[number]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	[number]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There are some complications this brings&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;This key is not singleton: many keys match to this property value &lt;code&gt;T&lt;/code&gt;. e.g. We want &lt;code&gt;x[0]&lt;/code&gt;, &lt;code&gt;x[5]&lt;/code&gt; etc to both yield &lt;code&gt;T&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;This key is not a string: we have to do a bit analysis to see if the key matches the &lt;code&gt;number&lt;/code&gt; type. &lt;code&gt;===&lt;/code&gt; does not cut the mustard&lt;/li&gt;
&lt;li&gt;Additionally we want to keep existing string key behaviour on the same type. Will still want accesses such as &lt;code&gt;x[&amp;quot;push&amp;quot;]&lt;/code&gt; to yield actual methods on the &lt;code&gt;Array&lt;/code&gt; type.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_objects#objects_and_properties&quot;&gt;In JavaScript all keys are strings (or symbols)&lt;/a&gt;. When we have a type here, it either depicts some generic, a string or something that coerces simple to a string (such as &lt;code&gt;number&lt;/code&gt; and &lt;code&gt;boolean&lt;/code&gt;).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;To support types as properties we need to expand the variants of key beyond a &lt;code&gt;String&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-diff&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FFA198&quot;&gt;- type PropertyKey = String;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+ enum PropertyKey&amp;lt;&amp;#39;a&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+     Constant(Cow&amp;lt;&amp;#39;a, str&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+     Type(TypeId)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+ }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #82071E&quot;&gt;- type PropertyKey = String;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+ enum PropertyKey&amp;lt;&amp;#39;a&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+     Constant(Cow&amp;lt;&amp;#39;a, str&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+     Type(TypeId)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+ }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;While we could have &lt;code&gt;PropertyKey = Constant(String) | NumberLike&lt;/code&gt;. We will use the &lt;code&gt;TypeId&lt;/code&gt; as it will handle more complex scenarios when we move on to the next part and further into mapped types.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;We use &lt;code&gt;Cow&amp;lt;&#39;a, str&amp;gt;&lt;/code&gt; because we use the &lt;code&gt;PropertyKey&lt;/code&gt; type in two places, one for storing properties where it &lt;code&gt;&#39;static&lt;/code&gt; (owned) and one for lookup where it uses an existing &lt;code&gt;&amp;amp;&#39;a str&lt;/code&gt; slice from the AST. Using &lt;code&gt;Cow&amp;lt;&#39;a, str&amp;gt;&lt;/code&gt; instead of &lt;code&gt;String&lt;/code&gt; makes it simple to reuse the definitions for both storage and lookup without cloning bytes unnecessarily (if we had a string member, we would have to &lt;code&gt;.to_owned()&lt;/code&gt; on AST just to perform a byte equality).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;generic-types-with-generic-property-keys&quot; tabindex=&quot;-1&quot;&gt;Generic types with generic property keys&lt;/h3&gt;
&lt;p&gt;Now that property key can point to a &lt;code&gt;Type&lt;/code&gt; (&lt;code&gt;TypeId&lt;/code&gt; is a pointer to a &lt;code&gt;Type&lt;/code&gt;) we can have a look at implementing the following &lt;a href=&quot;https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type&quot;&gt;&lt;code&gt;Record&lt;/code&gt; helper type&lt;/a&gt;. A &lt;code&gt;Record&lt;/code&gt; is object type who has keys of the type of generic &lt;code&gt;K&lt;/code&gt; with values in generic &lt;code&gt;V&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Record&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;K&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;V&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { [&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;K&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;V&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Record&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;K&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;V&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { [&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;K&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;V&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here the &lt;code&gt;Record&lt;/code&gt; type is represented in the system as a type alias with two generic parameters and a &lt;em&gt;single&lt;/em&gt; properties with the pairing &lt;code&gt;(PropertyKey::Type(*K*), *V*)&lt;/code&gt;. In this pseudo-representation.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Record &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;::Alias {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	name &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;Record&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	parameters &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;([ &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// 5 is type id string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;K&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; extends &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, id&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=*&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;101&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;), &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// 1 is type id any/unknown. &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;V&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; extends &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, id&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=*&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;102&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	])&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;AnonomousObjectLiteral&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// key of type K&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;				PropertyKey::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;101&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;), &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// value of type V&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;102&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Record &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;::Alias {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	name &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;Record&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	parameters &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;([ &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// 5 is type id string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;K&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; extends &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, id&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=*&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;101&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;), &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// 1 is type id any/unknown. &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;V&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; extends &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, id&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=*&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;102&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	])&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;AnonomousObjectLiteral&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// key of type K&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;				PropertyKey::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;101&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;), &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// value of type V&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;102&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now with our type we can instate it with some specific types. Let&#39;s say we are getting some data from an API which returns JSON. Once we have parsed the JSON we know from some assumptions that the results are &lt;code&gt;number&lt;/code&gt;. So we have a &lt;code&gt;Record&amp;lt;string, number&amp;gt;&lt;/code&gt;. We represent this using a &lt;a href=&quot;https://kaleidawave.github.io/posts/sets-types-and-type-checking/#partially-applied-generics&quot;&gt;partially applied generic&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Record&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;string, number&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;::PartiallyAppliedGeneric {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;on&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Record type without generic arguments&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;arguments&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;101&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// K = string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;102&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// V = number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Record&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;string, number&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;::PartiallyAppliedGeneric {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;on&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Record type without generic arguments&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;arguments&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;101&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// K = string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;102&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// V = number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;A &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map&quot;&gt;&lt;code&gt;Map&lt;/code&gt;&lt;/a&gt; would be a better data structure to use here, but we are doing working in the bounds of JavaScript with the untransformed output of &lt;code&gt;JSON.parse&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;During instantiation we also check that the first type argument &lt;code&gt;string&lt;/code&gt; extends &lt;code&gt;string&lt;/code&gt; (obviously holds as &lt;a href=&quot;https://kaleidawave.github.io/posts/sets-types-and-type-checking/#the-details&quot;&gt;subtyping is a reflexive relation&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Using the partially applied generic, we don&#39;t create a whole new object and substitute values, we just pair the &lt;code&gt;Record&lt;/code&gt; &lt;em&gt;template&lt;/em&gt; with some values.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This step is exactly the same as regular generic objects, nothing new for mapped types just yet.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;recording-generics-with-the-generic-chain&quot; tabindex=&quot;-1&quot;&gt;Recording generics with the generic chain&lt;/h3&gt;
&lt;p&gt;Before we can understand how we can access property keys that are generic types, will take a short deep dive into how reading the wrapped generics works.&lt;/p&gt;
&lt;p&gt;We know that &lt;code&gt;Box&amp;lt;number&amp;gt;&lt;/code&gt; is a pairing of the &lt;code&gt;Box&lt;/code&gt; type with a map of type arguments to type parameters (e.g. &lt;code&gt;Box&amp;lt;number&amp;gt; = (Box, T = number)&lt;/code&gt;). When we get a property from this type, we split off the generic arguments and store them in a table. We then look for the property on the &lt;em&gt;naked&lt;/em&gt; generic type. If we find a value here we return it with the current chain table. For the following&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; { &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;inner&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getInner&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;box&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; box.inner&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; { &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;inner&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getInner&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;box&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; box.inner&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The process is something like&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We start by requesting the &lt;code&gt;&amp;quot;inner&amp;quot;&lt;/code&gt; property on &lt;code&gt;Box&amp;lt;number&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;We unfold the type arguments and so we now look for &lt;code&gt;&amp;quot;inner&amp;quot;&lt;/code&gt; on &lt;code&gt;Box&lt;/code&gt; with &lt;code&gt;substitutions: [(T, number)]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;In this example &lt;code&gt;&amp;quot;inner&amp;quot;&lt;/code&gt; &lt;strong&gt;does&lt;/strong&gt; exist on &lt;code&gt;Box&lt;/code&gt; so we return &lt;code&gt;Logical::Implies { result: PropertyValue::Value(T), substitutions }&lt;/code&gt; where we also send our &lt;code&gt;substitutions&lt;/code&gt; chain with the result&lt;/li&gt;
&lt;li&gt;After lookup we found a valid result &lt;code&gt;T&lt;/code&gt;. We find there are some substitutions we scan &lt;code&gt;T&lt;/code&gt; and follow any lookups from the &lt;code&gt;substitutions: [(T, number)]&lt;/code&gt; list.&lt;/li&gt;
&lt;li&gt;We find a &lt;code&gt;T&lt;/code&gt; can be substituted with &lt;code&gt;number&lt;/code&gt; and so return &lt;code&gt;number&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;We return a &lt;code&gt;Logical::Implies&lt;/code&gt; adjoined with substitutions in a middle step because it works better in Rust&#39;s borrow checking. While in this case the substitution was a simple swap, in other cases we need to register new types and is easiest to create new types (mutate the store) only &lt;strong&gt;after&lt;/strong&gt; the traversal of current types has finished.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;subtyping-with-generics&quot; tabindex=&quot;-1&quot;&gt;Subtyping with generics&lt;/h3&gt;
&lt;p&gt;Above we used the &lt;code&gt;GenericChain&lt;/code&gt; for lookup. We also use this structure for subtyping of generic items.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; { &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;inner&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;numbers&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { inner: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;not number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; { &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;inner&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;numbers&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { inner: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;not number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When checking (subtyping) the following happens with the table. (each line &lt;em&gt;somewhat&lt;/em&gt; represents call to the &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/16f7779b157dea4da2b618d8e192492a09d1acb9/checker/src/types/subtyping.rs#L221&quot;&gt;&lt;code&gt;is_subtype&lt;/code&gt; function&lt;/a&gt;)&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                            :&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { inner: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;not number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Unfold the `number` argument&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;inner&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }         (with &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; number) :&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { inner: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;not number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// iterating over properties on the LHS. We only have `inner` property&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;inner&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;inner&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;   (with &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; number) :&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { inner: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;not number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }.inner&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    (with &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; number) :&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;not number&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Replace T with number here using this chain&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;               (with &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; number) :&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;not number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// &amp;lt;- subtyping returns here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                            :&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { inner: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;not number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Unfold the `number` argument&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;inner&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }         (with &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; number) :&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { inner: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;not number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// iterating over properties on the LHS. We only have `inner` property&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;inner&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;inner&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;   (with &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; number) :&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { inner: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;not number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }.inner&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    (with &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; number) :&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;not number&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Replace T with number here using this chain&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;               (with &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; number) :&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;not number&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// &amp;lt;- subtyping returns here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the above we see that the LHS unfolds its generics and so we can reduce them out to checking on the &lt;em&gt;leaves&lt;/em&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Note the RHS can also produce a table if it is generic.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In the above example I simplified &lt;code&gt;substitutions&lt;/code&gt; to just be a list. In the actual code this is called &lt;code&gt;GenericChain&lt;/code&gt; and is a linked list of substitution lists. This allows it to do nested generics. So the following is valid.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;parent&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;null&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;inner&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;myBox&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { parent: { parent: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, inner: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }, inner: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;heya&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;parent&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;null&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;inner&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;myBox&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { parent: { parent: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, inner: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }, inner: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;heya&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Checking&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                            :&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;with&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; string)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;with&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; string) (&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; number) :&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;       &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;with&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; string) (&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; number) :&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// We pick the first from the right&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                 :&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Checking&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                            :&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;with&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; string)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;with&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; string) (&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; number) :&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;       &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;with&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; string) (&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; number) :&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// We pick the first from the right&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #953800&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                 :&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Additionally &lt;code&gt;GenericChain&lt;/code&gt; uses lifetimes of arguments rather than cloning lists (and thus allocating).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;testing-generic-keys&quot; tabindex=&quot;-1&quot;&gt;Testing generic keys&lt;/h3&gt;
&lt;p&gt;Given we now have these generics basics out of the way, we have to define what these type representations contain.&lt;/p&gt;
&lt;p&gt;It starts to get more complicated for type keys. One case of this is the &lt;code&gt;Array&lt;/code&gt; type. As previously stated the &lt;code&gt;Array&lt;/code&gt; type has a numeric property and for this we can&#39;t really use equality. :/&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(TypeId::&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;NUMBER_TYPE&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(Cow::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Borrowed&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(TypeId::&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;NUMBER_TYPE&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(Cow::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Borrowed&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So instead we need to make a special function for key validity that we can put into the lookup function.&lt;/p&gt;
&lt;p&gt;This is where the complications start. While we could use &lt;code&gt;type_is_subtype&lt;/code&gt; we don&#39;t have two &lt;code&gt;TypeId&lt;/code&gt;s as we sometimes have a &lt;code&gt;PropertyKey::String&lt;/code&gt; on a side. We also have a problem in the above example. &lt;code&gt;&amp;quot;1&amp;quot;&lt;/code&gt; is string not a number, so we have to add catch for the implicit conversion JavaScript when assigning and reading properties with keys that are numbers.&lt;/p&gt;
&lt;p&gt;Unfortunately we do have a have some duplication of some logic but we have a function like&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;key_matches&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	base&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	want&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;	// simple case&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(base), &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(want))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (base, want) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; base &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; want&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;	// catch for number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;NUMBER_TYPE&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;), &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(want)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (base, want) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; want&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_ok&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;	// delegate to regular subtyping&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(base), &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(want)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (base, want) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;type_is_subtype&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(base, want)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_subtype&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;key_matches&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	base&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	want&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;	// simple case&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(base), &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(want))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (base, want) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; base &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; want&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;	// catch for number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;NUMBER_TYPE&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;), &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(want)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (base, want) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; want&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;usize&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_ok&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;	// delegate to regular subtyping&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(base), &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(want)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (base, want) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;type_is_subtype&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(base, want)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_subtype&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Full &lt;code&gt;key_matches&lt;/code&gt; function &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/e6f6ffd7cb48285cdaaf7e57e4d636bbaf038b03/checker/src/types/subtyping.rs#L2460-L2462&quot;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;We could create &lt;code&gt;PartialEq&lt;/code&gt; implementation but 1) it is not equality, as it involves subtyping and 2) as we will see in a minute this function will start to take a few more parameters and as we are only fixed to LHS and RHS parameters in &lt;code&gt;PartialEq::eq&lt;/code&gt; we will we use a function instead&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;passing-generics-through-key_matches&quot; tabindex=&quot;-1&quot;&gt;Passing generics through &lt;code&gt;key_matches&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;In our initial &lt;code&gt;Record&lt;/code&gt; example we have a key that is a generic parameter. With the above we have a problem as we do subtyping on &lt;code&gt;K&lt;/code&gt; but we don&#39;t have a value for &lt;code&gt;K&lt;/code&gt;. Our &lt;code&gt;key_matches&lt;/code&gt; function isn&#39;t aware of type parameters.&lt;/p&gt;
&lt;p&gt;So we modify &lt;code&gt;key_matches&lt;/code&gt; function to allow generic arguments down. This base generics will contain a list which has the &lt;code&gt;K=string&lt;/code&gt; pair in. When we do subtyping we find a &lt;code&gt;K&lt;/code&gt; on the LHS, and using our list we pass down, &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/e6f6ffd7cb48285cdaaf7e57e4d636bbaf038b03/checker/src/types/subtyping.rs#L2500&quot;&gt;we look up the argument for &lt;code&gt;K&lt;/code&gt;&lt;/a&gt; and find &lt;code&gt;string&lt;/code&gt;. Therefore if &lt;code&gt;want&lt;/code&gt; is a string like property key then the &lt;code&gt;key_matches&lt;/code&gt; function returns in this example &lt;code&gt;true&lt;/code&gt;!&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;key_matches&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	(base, base_generics)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;GenericChain&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	(want, want_generics)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;GenericChain&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;	// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(base), &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(want)) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (base, want) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;type_is_subtype&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;((base, base_generics), (want, want_generics))&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_subtype&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;key_matches&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	(base, base_generics)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;GenericChain&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	(want, want_generics)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;GenericChain&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;	// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(base), &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(want)) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (base, want) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;type_is_subtype&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;((base, base_generics), (want, want_generics))&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_subtype&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When this returns &lt;code&gt;true&lt;/code&gt; we now have the following lookup. As it returns true, we yield the value and this in turn is returned with the chain so that we can substitute values in.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// From `Record&amp;lt;string, number&amp;gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; base_generic_chain &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;K&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;STRING_TYPE&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;V&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;NUMBER_TYPE&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; want_key &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Cow&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Borrowed&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;something&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; base_properties&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find_map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(key, value)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;key_matches&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;((key, base_generic_chain), (want_key, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;then_some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(value)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Result&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	 value,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	 substitutions&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; base_generic_chain&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// From `Record&amp;lt;string, number&amp;gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; base_generic_chain &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;K&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;STRING_TYPE&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;V&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;NUMBER_TYPE&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; want_key &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Cow&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Borrowed&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;something&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; base_properties&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;rev&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find_map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(key, value)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;key_matches&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;((key, base_generic_chain), (want_key, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;then_some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(value)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Result&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	 value,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	 substitutions&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; base_generic_chain&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is how &lt;code&gt;Record&amp;lt;string, numbers&amp;gt;&lt;/code&gt; works. It isn&#39;t quite a mapped type yet, but hopefully you have a bit more of an understanding of generics to see how this works now.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Additionally I hope you can see why the properties are stored as a &lt;code&gt;Vec&lt;/code&gt; here (rather than a &lt;code&gt;HashMap&lt;/code&gt;). Not only is it a little overkill for the average &amp;lt; 10 key based object. There isn&#39;t a simple hash and equality relation for when keys based on types are in the picture.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;on-to-mapped-keys&quot; tabindex=&quot;-1&quot;&gt;On to mapped keys&lt;/h2&gt;
&lt;h3 id=&quot;real-mapped-types&quot; tabindex=&quot;-1&quot;&gt;Real mapped types&lt;/h3&gt;
&lt;p&gt;So far we have covered constant keys and keys that are passed from above via a generic.&lt;/p&gt;
&lt;h3 class=&quot;center&quot;&gt;&lt;p&gt;(real) Mapped types are when the property value is based on the type of a property key.&lt;/p&gt;
&lt;/h3&gt;
&lt;p&gt;We do this using the &lt;code&gt;[ParameterName in ...]: Value&lt;/code&gt; syntax for a property. Here &lt;code&gt;ParameterName&lt;/code&gt; is a new generic parameter (similar to that on functions or interfaces). It is can be used as a value in the &lt;code&gt;Value&lt;/code&gt; type annotation.&lt;/p&gt;
&lt;p&gt;For example, in the following we build a type that &lt;em&gt;maps&lt;/em&gt; over the keys of &lt;code&gt;Event&lt;/code&gt; and builds a &lt;strong&gt;new&lt;/strong&gt; type where each field might be &lt;code&gt;null&lt;/code&gt;. We can see it uses type &lt;code&gt;P&lt;/code&gt; as a inline property generic. We use &lt;code&gt;in&lt;/code&gt; to say it must extend the type &lt;code&gt;keyof Event&lt;/code&gt; (covered more in a minute). We use this generic &lt;code&gt;P&lt;/code&gt; in the property value to depict the result is the associate value of &lt;code&gt;Event[P]&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Event&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Date&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;EventButFieldsPossiblyNull&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Event&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Event&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;null&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Event&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Date&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;EventButFieldsPossiblyNull&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Event&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Event&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;null&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We have &lt;strong&gt;mapped&lt;/strong&gt; each property to a new value using &lt;code&gt;P&lt;/code&gt; as a parameter.&lt;/p&gt;
&lt;p&gt;This practise is normally parameterised and used for utility types.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TButFieldsPossiblyNull&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;null&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TButFieldsPossiblyNull&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;null&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;They are a niche feature, but like many other abstractions they can be useful when&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Don&#39;t want to copy out definitions of existing items&lt;/li&gt;
&lt;li&gt;Keeping definitions up-to date/inline within related definitions&lt;/li&gt;
&lt;li&gt;Working on top of definitions we don&#39;t own (external or generated etc)&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;Again this partial applied. &amp;quot;creating&amp;quot; a mapped type does not walk the properties, it just creates a partially applied generic. This reduces overhead on instantiation, but moves complexity to usage and means that each usage has to do some work.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;important-functionality%3A-inferring-type-argument-values&quot; tabindex=&quot;-1&quot;&gt;Important functionality: Inferring type argument values&lt;/h4&gt;
&lt;p&gt;Before talking about the access part. I will talk about a new kind &lt;strong&gt;kind&lt;/strong&gt; of generic recording. We previously saw how type arguments on a structure are passed down through access and subtyping with &lt;code&gt;GenericChain&lt;/code&gt; the table like structure.&lt;/p&gt;
&lt;p&gt;There are cases where we have a generic but don&#39;t have a value for it. Instead we need to &lt;strong&gt;infer its value based on usage&lt;/strong&gt;. This is where &lt;code&gt;Contributions&lt;/code&gt; comes in.&lt;/p&gt;
&lt;p&gt;For example given the function&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;declare&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;idString&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;declare&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;idString&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When we call it with &lt;code&gt;idString(&amp;quot;Hello World&amp;quot;)&lt;/code&gt; we want to find a type for this expression and this requires knowing figuring out the returned type. In this example we need to infer &lt;code&gt;T&lt;/code&gt; to have the value &lt;code&gt;&amp;quot;Hello World&amp;quot;&lt;/code&gt;, which we will then use to substitute as the return type.&lt;/p&gt;
&lt;p&gt;The implementation to do lies in &lt;s&gt;making&lt;/s&gt; subtyping &lt;s&gt;more complex&lt;/s&gt;. When we call a function we subtype each argument value against its respective parameter type. In this case we run &lt;code&gt;(T extends string) :&amp;gt; &amp;quot;Hello World&amp;quot;&lt;/code&gt;. The inner steps are as follows&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We find that the LHS &lt;code&gt;T&lt;/code&gt; is a (substitutable) generic parameter&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;We find that it does not have a value in the LHS &lt;code&gt;GenericChain&lt;/code&gt; so continue to subtype the generic&lt;/strong&gt; (there is no &lt;code&gt;GenericChain&lt;/code&gt; in this example).&lt;/li&gt;
&lt;li&gt;We also do not find for this &lt;code&gt;FunctionGeneric&lt;/code&gt; that there is a explicit call side type argument in &lt;code&gt;state.call_site_type_arguments&lt;/code&gt; so continue to subtype the generic&lt;/li&gt;
&lt;li&gt;For generics &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/16f7779b157dea4da2b618d8e192492a09d1acb9/checker/src/types/subtyping.rs#L615-L620&quot;&gt;we check the extends constraint&lt;/a&gt; (if there was no extends annotation, this annotation would extend &lt;code&gt;any&lt;/code&gt; and so this check always passes)&lt;/li&gt;
&lt;li&gt;We find the constraint check passed (&lt;code&gt;&amp;quot;Hello World&amp;quot;&lt;/code&gt; does indeed extend &lt;code&gt;string&lt;/code&gt;!)&lt;/li&gt;
&lt;li&gt;The important part: take our LHS generic type &lt;code&gt;T&lt;/code&gt; and RHS type &lt;code&gt;&amp;quot;Hello World&amp;quot;&lt;/code&gt; and &lt;strong&gt;we append &lt;code&gt;T=&amp;quot;Hello World&amp;quot;&lt;/code&gt; as a tuple pair into the &lt;code&gt;contributions&lt;/code&gt; list in state&lt;/strong&gt;. Something like &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/16f7779b157dea4da2b618d8e192492a09d1acb9/checker/src/types/subtyping.rs#L628-L629&quot;&gt;&lt;code&gt;contributions.push((lhs, rhs))&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;Contributions&lt;/code&gt; is inside the &lt;code&gt;subtyping::State&lt;/code&gt; structure which is passed through the &lt;code&gt;is_subtype&lt;/code&gt; function (as well as the generic chains).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;There are some fun details with contributions such as dropping cases with union types when a branch fails. We can also see that through the &lt;code&gt;NoInfer&lt;/code&gt; intrinsic the results are dropped. This is why they are internally held as &lt;code&gt;Vec&lt;/code&gt; because that is easy to drop ranges from as it is ordered.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;By doing it this way it allows inference to be done in the same &lt;em&gt;scan&lt;/em&gt; by the type checker. Although this if faster and simpler, it does have &lt;em&gt;complications&lt;/em&gt; (not impossible though) for inference that uses parameters before a value to the right has been checked and inferred.&lt;/p&gt;
&lt;h4 id=&quot;mapped-keys%3A-the-identity-key-case&quot; tabindex=&quot;-1&quot;&gt;Mapped keys: The identity key case&lt;/h4&gt;
&lt;p&gt;After you have passed inference 101 above, you should be good to go for getting you head around how mapped types work.&lt;/p&gt;
&lt;p&gt;We will start of with the &lt;em&gt;identity&lt;/em&gt; mapped type.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;IdOnKeys&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { [&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;IdOnKeys&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { [&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When accessing &lt;code&gt;[&amp;quot;a&amp;quot;]&lt;/code&gt; it goes through the steps outlined above&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First as one of the side is &lt;code&gt;key_matches&lt;/code&gt; it goes to subtype (or something like subtyping),&lt;/li&gt;
&lt;li&gt;There is no value for &lt;code&gt;P&lt;/code&gt; in the &lt;code&gt;GenericChain&lt;/code&gt; (it is not passed from above and also it is marked as a &lt;code&gt;MappedGeneric&lt;/code&gt; type) so we go to generic contributions&lt;/li&gt;
&lt;li&gt;&lt;code&gt;P in string&lt;/code&gt; implies &lt;code&gt;P extends string&lt;/code&gt; and we have that &lt;code&gt;&amp;quot;a&amp;quot;&lt;/code&gt; is a string so we continue&lt;/li&gt;
&lt;li&gt;In this case we add &lt;code&gt;P = &amp;quot;a&amp;quot;&lt;/code&gt; to the contributions! The argument for generic parameter &lt;code&gt;P&lt;/code&gt; is inferred to be the type &lt;code&gt;&amp;quot;a&amp;quot;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now we have our pairing we need to make the access aware of this value. To do this we expand on our &lt;code&gt;GenericChain&lt;/code&gt; table and pass &lt;code&gt;*[(P, &amp;quot;a&amp;quot;)]*&lt;/code&gt; to the value resolution.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=2hwcga&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/identity-mapped-type-on-keys.png&quot; alt=&quot;identity-mapped-type-on-keys&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;One of the problems when attempting the addition of this feature is that inference/contributions is a a &lt;code&gt;TypeId&lt;/code&gt; to &lt;code&gt;TypeId&lt;/code&gt; paring. When accessing a property key we can have be passed &lt;code&gt;PropertyKey::String&lt;/code&gt; which is not a type. We are a bit stuck as we cannot create a new type during subtyping as that would conflicts with the borrow checker (we would require a mutable reference to &lt;code&gt;TypeStore&lt;/code&gt; and during subtyping we only have a immutable reference to the bank of types). So like so many problems faced with types, it turned out the checker needed a new pseudo type.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;To work around allowing &lt;code&gt;TypeId &amp;lt;- String&lt;/code&gt; contributions I introduced the new &lt;strong&gt;&lt;code&gt;CovariantContribution&lt;/code&gt; enum to the contribution system&lt;/strong&gt;. This structure has more variants and so is effectively &lt;code&gt;TypeId | String | ...&lt;/code&gt; and like other things delegates later steps to creating a type.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;mapped-types%3A-the-identity-map-case&quot; tabindex=&quot;-1&quot;&gt;Mapped types: the identity map case&lt;/h4&gt;
&lt;p&gt;The above shows a basic example of the mapping parameter keys. We will now step up in complexity to cover some more useful mapped types. The first is the identity map on objects. It takes a object and producing another object with the same keys mapping to the same values.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;IdentityOnObject&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;IdentityOnObject&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;While this has no effect, we can see how we can now modify this above example to give it more use by applying type operations to the property key or value type.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Pick&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ToPick&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ToPick&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Omit&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ToOmit&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Not&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ToOmit&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;)]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;MakeArray&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Pick&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ToPick&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ToPick&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Omit&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ToOmit&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Not&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ToOmit&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;)]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;MakeArray&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;While you can use the TypeScript &lt;code&gt;Exclude&lt;/code&gt; type and &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/specification/specification.md#infer-and-extends-distribution&quot;&gt;it works in Ezno&lt;/a&gt;, I think it is simpler to use the new &lt;a href=&quot;https://kaleidawave.github.io/posts/experimental-types/#the-not-type&quot;&gt;&lt;code&gt;Not&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;key-type-modifiers%3A-in-and-as-syntax&quot; tabindex=&quot;-1&quot;&gt;Key type modifiers: &lt;code&gt;in&lt;/code&gt; and &lt;code&gt;as&lt;/code&gt; syntax&lt;/h4&gt;
&lt;p&gt;Mapped types can have special syntax in the property position.&lt;/p&gt;
&lt;p&gt;In the first example, it is quite simple to see &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/16f7779b157dea4da2b618d8e192492a09d1acb9/checker/src/synthesis/interfaces.rs#L321-L331&quot;&gt;&lt;code&gt;K in T&lt;/code&gt; implies &lt;code&gt;K extends T&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The harder code syntax is &lt;code&gt;as&lt;/code&gt;. At first it got me scratching my head. But I figured that rewrites the key.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PrefixKeys&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    [&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ((&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`property_${&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PrefixKeys&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    [&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ((&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`property_${&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For the identity on properties we have the property key as &lt;code&gt;infer P&lt;/code&gt;, for the identity on objects we have a key of type &lt;code&gt;infer P extends keyof T&lt;/code&gt;. For this example we put insert &lt;code&gt;P&lt;/code&gt; into the RHS type and so have &lt;code&gt;property_${infer P extends ((keyof T) &amp;amp; string)}&lt;/code&gt;. In total this is a &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/16f7779b157dea4da2b618d8e192492a09d1acb9/checker/src/synthesis/interfaces.rs#L336-L339&quot;&gt;three line addition&lt;/a&gt; we already have the &lt;code&gt;P&lt;/code&gt; type in the namespace for the RHS type synthesis.&lt;/p&gt;
&lt;h2 id=&quot;more-advanced-property-values&quot; tabindex=&quot;-1&quot;&gt;More advanced property values&lt;/h2&gt;
&lt;p&gt;So far we have only seen properties having the value being a exact type. To discuss the last parts of mapped types we need to expand on the variants of &lt;code&gt;PropertyValue&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-diff&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FFA198&quot;&gt;- type PropertyValue = TypeId;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+ enum PropertyValue {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+     /// Simple&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+     Value(TypeId),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+     /// from `get` and `set`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+     GetterSetter {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+         getter: Box&amp;lt;FunctionType&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+         setter: Box&amp;lt;FunctionType&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+     }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+ &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+     ///&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+     ConditionallyExists {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+         condition: TypeId,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+         value: Box&amp;lt;Self&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+     }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+ &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+     ///&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+     Configured {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+         writable: TypeId,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+         // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+         value: Box&amp;lt;Self&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+     }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;+ }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #82071E&quot;&gt;- type PropertyValue = TypeId;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+ enum PropertyValue {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+     /// Simple&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+     Value(TypeId),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+     /// from `get` and `set`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+     GetterSetter {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+         getter: Box&amp;lt;FunctionType&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+         setter: Box&amp;lt;FunctionType&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+     }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+ &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+     ///&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+     ConditionallyExists {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+         condition: TypeId,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+         value: Box&amp;lt;Self&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+     }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+ &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+     ///&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+     Configured {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+         writable: TypeId,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+         // ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+         value: Box&amp;lt;Self&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+     }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;+ }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The simple case becomes the main variant. We also introduce &lt;code&gt;get&lt;/code&gt; and &lt;code&gt;set&lt;/code&gt; functions in here, we handle them specially but that is for another blog post.&lt;/p&gt;
&lt;p&gt;The two newer additions are &lt;code&gt;PropertyValue::ConditionallyExists&lt;/code&gt; and &lt;code&gt;PropertyValue::Configured&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;propertyvalue%3A%3Aconditionallyexists&quot; tabindex=&quot;-1&quot;&gt;&lt;code&gt;PropertyValue::ConditionallyExists&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;A property can conditionally exist via adding the &lt;code&gt;?&lt;/code&gt; prefix modifier to property declaration.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;MappedTypes&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;fun&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;YES!&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;MappedTypes&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;fun&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;YES!&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;This declaration is different to &lt;code&gt;fun: &amp;quot;YES!&amp;quot; | undefined&lt;/code&gt; as in this case &lt;code&gt;fun in obj&lt;/code&gt; is always &lt;code&gt;true&lt;/code&gt;, whereas in the above example it is conditional. Here we say that condition for it existing is &lt;em&gt;unknown&lt;/em&gt; and use the &lt;code&gt;boolean&lt;/code&gt; type in its place.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This variant can represent actual JavaScript code&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (condition) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	obj.prop &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// obj.prop conditionally exists (value = 2) based on `condition`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (condition) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	obj.prop &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// obj.prop conditionally exists (value = 2) based on `condition`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we see that &lt;code&gt;&amp;quot;prop&amp;quot; in obj&lt;/code&gt; is only &lt;code&gt;true&lt;/code&gt; when &lt;code&gt;condition&lt;/code&gt; is truthy. When we access this property we allow retrieve it but we do union the result with &lt;code&gt;undefined&lt;/code&gt; for the user to account for later.&lt;/p&gt;
&lt;h3 id=&quot;propertyvalue%3A%3Aconfigured&quot; tabindex=&quot;-1&quot;&gt;&lt;code&gt;PropertyValue::Configured&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;The second new &lt;code&gt;PropertyValue&lt;/code&gt; variant is a configured wrapper. In JavaScript &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor&quot;&gt;every property has a descriptor&lt;/a&gt;. The usage of the these descriptors is quite low. However they crop up in standard library items (&lt;a href=&quot;https://developer.chrome.com/blog/smooshgate/&quot;&gt;normally causing problems&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;We can (ab)use the &lt;code&gt;writable&lt;/code&gt; value of a property to mark a property as readonly. We say that when &lt;code&gt;writable&lt;/code&gt; is &lt;code&gt;false&lt;/code&gt; we cannot assign to it. For example if the &lt;code&gt;x&lt;/code&gt; property is not writable, then &lt;code&gt;.x = 2&lt;/code&gt; will fail.&lt;/p&gt;
&lt;p&gt;So given a property declaration prefixed with &lt;code&gt;readonly&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Item&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;readonly&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Item&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;readonly&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;we define the properties as something like&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;id&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, PropertyValue::Configured { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		value: PropertyValue::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(TypeId::&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;STRING_TYPE&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		writable: TypeId::&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;FALSE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;count&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, PropertyValue::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(TypeId::&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;NUMBER_TYPE&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;id&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, PropertyValue::Configured { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		value: PropertyValue::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(TypeId::&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;STRING_TYPE&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		writable: TypeId::&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;FALSE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;count&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, PropertyValue::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(TypeId::&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;NUMBER_TYPE&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and do not allow writing to it&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=2rvy0y&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/cannot-write-to-readonly-from-annotation.png&quot; alt=&quot;cannot-write-to-readonly-from-annotation&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;There is a bit of nuance here around TypeScript &lt;code&gt;readonly&lt;/code&gt; and JavaScript &lt;code&gt;writeable&lt;/code&gt;. TypeScript&#39;s &lt;code&gt;readonly&lt;/code&gt; is a developer abstraction, which has no effect on compile time. &lt;code&gt;writeable&lt;/code&gt; on the other hand is part of JavaScript execution and has runtime behaviour when looked up &lt;code&gt;Object.getPropertyDescriptor&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Most people prefer the upfront warnings of readonly, rather than marking it as immutable. JavaScript &lt;code&gt;writable&lt;/code&gt; is hard to do compile introspection (but not impossible as showcased later), so TypeScript added their own syntax and system to add this case.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;There are others here, but we skip over them for now&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;mapping-modifiers%3A-default-behaviour&quot; tabindex=&quot;-1&quot;&gt;Mapping Modifiers: Default behaviour&lt;/h3&gt;
&lt;p&gt;When we have a mapped key that uses extends, &lt;strong&gt;we have to carry over these conditional and writeable modifiers&lt;/strong&gt;. For example given&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;AllValuesString&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;AllValuesString&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then if we have &lt;code&gt;AllValuesString&amp;lt;{ a?: number, readonly b: boolean }&amp;gt;&lt;/code&gt; then the resulting type &lt;strong&gt;is actually &lt;code&gt;{ a?: string, readonly b: string }&lt;/code&gt;&lt;/strong&gt;!&lt;/p&gt;
&lt;p&gt;This seems incredible complicated to implement at first, but it is possible.&lt;/p&gt;
&lt;p&gt;In the implementation in Ezno, at the mapped type definition: if the key extends a &lt;code&gt;keyof ...&lt;/code&gt; modifier, the resultant property is modified to be based on two special parameters &lt;code&gt;TypeId::WRITABLE_KEY_ARGUMENT&lt;/code&gt; and &lt;code&gt;TypeId::NON_OPTIONAL_KEY_ARGUMENT&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; rhs &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;references_key_of&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(mapped_type&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;extends) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	rhs &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ConditionallyExists&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		condition&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;NON_OPTIONAL_KEY_ARGUMENT&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Configured&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; rhs, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			writeable&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;WRITABLE_KEY_ARGUMENT&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; rhs &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;references_key_of&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(mapped_type&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;extends) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	rhs &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ConditionallyExists&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		condition&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;NON_OPTIONAL_KEY_ARGUMENT&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Configured&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; rhs, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			writeable&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;WRITABLE_KEY_ARGUMENT&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here the property is made conditional and configured based on two special types. We can treat them as parameters. We need to infer whether they are true or false based om &lt;code&gt;keyof&lt;/code&gt; returns.&lt;/p&gt;
&lt;p&gt;So the next part is to connect this up from the other side. When doing subtyping for key matching, if we test against a &lt;code&gt;keyof&lt;/code&gt; type, &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/16f7779b157dea4da2b618d8e192492a09d1acb9/checker/src/types/subtyping.rs#L2851-L2891&quot;&gt;two arguments are set into the inferred table against for these internal parameters &lt;code&gt;TypeId::WRITABLE_KEY_ARGUMENT&lt;/code&gt; and &lt;code&gt;TypeId::NON_OPTIONAL_KEY_ARGUMENT&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;When we get a property out the &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/16f7779b157dea4da2b618d8e192492a09d1acb9/checker/src/types/properties/access.rs#L966-L977&quot;&gt;other side we match these up and specialise them&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;mapped-type-modifiers%3A-property-descriptor-and-conditionally-exists&quot; tabindex=&quot;-1&quot;&gt;Mapped type modifiers: Property descriptor and conditionally exists&lt;/h3&gt;
&lt;p&gt;So we have the default case out of the way. We can change the mapping-ness and enforce cases using special syntax.&lt;/p&gt;
&lt;p&gt;For optionality with &lt;code&gt;?:&lt;/code&gt;, we set &lt;code&gt;condition: TypeId::TRUE&lt;/code&gt; in the conditional wrapper (rather than the special mapping parameter type)&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Partial&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Partial&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here because of the &lt;code&gt;-?:&lt;/code&gt; we &lt;strong&gt;do not add&lt;/strong&gt; the conditional wrapper&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Required&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-?:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Required&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-?:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here with the &lt;code&gt;readonly&lt;/code&gt; prefix we set &lt;code&gt;readonly: TypeId::TRUE&lt;/code&gt; in the configurable wrapper (rather than the special mapping parameter type)&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Immutable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;readonly&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Immutable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;readonly&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here because of &lt;code&gt;-readonly&lt;/code&gt; we &lt;strong&gt;do not add&lt;/strong&gt; the configurable readonly wrapper!&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Mutable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-readonly&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Mutable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-readonly&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/16f7779b157dea4da2b618d8e192492a09d1acb9/checker/src/synthesis/interfaces.rs#L364-L395&quot;&gt;Full logic here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And that concludes the mapped type section. Let me know in the comments if there is any mapped type feature I have missed.&lt;/p&gt;
&lt;p&gt;The next parts go into some really interesting and important things about properties and more types!&lt;/p&gt;
&lt;h2 id=&quot;string-intrinsics%3A-uppercase%2C-lowercase%2C-etc&quot; tabindex=&quot;-1&quot;&gt;String intrinsics: &lt;code&gt;Uppercase&lt;/code&gt;, &lt;code&gt;Lowercase&lt;/code&gt;, etc&lt;/h2&gt;
&lt;p&gt;When working on mapped types, I noticed some examples used &lt;a href=&quot;https://www.typescriptlang.org/docs/handbook/utility-types.html#intrinsic-string-manipulation-types&quot;&gt;special string transforms&lt;/a&gt; in their &lt;code&gt;as&lt;/code&gt; clause. We can pass constant strings to these transformer types.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Uppercase&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;HI&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Lowercase&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Type error: &amp;quot;example&amp;quot; is not assignable to &amp;quot;EXAMPLE&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;z&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Uppercase&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;Example&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;example&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Uppercase&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;HI&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Lowercase&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Type error: &amp;quot;example&amp;quot; is not assignable to &amp;quot;EXAMPLE&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;z&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Uppercase&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;Example&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;example&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There are a few things that were implemented during this step&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Eagerly apply the transformation, including through union types (&lt;code&gt;Uppercase&amp;lt;&amp;quot;a&amp;quot; | &amp;quot;b&amp;quot;&amp;gt; = &amp;quot;A&amp;quot; | &amp;quot;B&amp;quot;&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Apply when used on a generic for a return type&lt;/li&gt;
&lt;li&gt;Subtyping.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Similar to other intrinsics, when we encounter this we have custom logic for these situations.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;If anyone has a neat way to do case insensitive string equality that is better than &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/16f7779b157dea4da2b618d8e192492a09d1acb9/checker/src/types/subtyping.rs#L2614C5-L2614C55&quot;&gt;&lt;code&gt;lhs.to_lowercase() == rhs.to_lowercase()&lt;/code&gt;&lt;/a&gt; then &lt;a href=&quot;https://github.com/kaleidawave/ezno/compare&quot;&gt;please send a PR 😁🙏&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;introducing-my-own-intrinsic%3A-caseinsensitive&quot; tabindex=&quot;-1&quot;&gt;Introducing my own intrinsic: &lt;code&gt;CaseInsensitive&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;One example that got me confused.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Item&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;iD&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;MappedItem&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    [&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Item&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Uppercase&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Item&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Item&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;iD&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;MappedItem&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    [&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;keyof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Item&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Uppercase&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Item&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we have a property of type &lt;code&gt;Uppercase&amp;lt;infer P extends keyof Event&amp;gt;&lt;/code&gt;. We can pull out the problem here and I will give you an equivalent problem: what the return type is here?.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;declare&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Uppercase&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;) -&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;declare&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Uppercase&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;) -&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We see that we have to infer through this &lt;code&gt;Uppercase&lt;/code&gt; boundary. For it to be valid you expect &lt;code&gt;func(&amp;quot;hi&amp;quot;)&lt;/code&gt; to return all four valid values for &lt;code&gt;T&lt;/code&gt;: &lt;code&gt;&amp;quot;hi&amp;quot;, &amp;quot;Hi&amp;quot;, &amp;quot;hI&amp;quot;, &amp;quot;HI&amp;quot;&lt;/code&gt;. To support this I added &lt;code&gt;CaseInsensitive&lt;/code&gt;. The result is that if a inferred pair is found inside one of these case transformations then we wrap the output in &lt;code&gt;CaseInsensitive&lt;/code&gt; to pick up all valid cases.&lt;/p&gt;
&lt;p&gt;After adding similar subtyping logic, this fixes the problem.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I think I had to do it this way because I am doing it via inference via &lt;code&gt;key_matches&lt;/code&gt; whereas TypeScript eagerly evaluates mapped types and so eagerly generates these variants.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;If you like intrinsics, check out the &lt;a href=&quot;https://kaleidawave.github.io/posts/experimental-types&quot;&gt;last blog post&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Switching it up, here are some other things I have been working on properties.&lt;/p&gt;
&lt;h2 id=&quot;functions-and-object.keys&quot; tabindex=&quot;-1&quot;&gt;Functions and &lt;code&gt;Object.keys&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;We will now take a peek at the crazier side of the checker. One of the biggest experimental features is the &lt;em&gt;observance of side-effects&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In some &lt;em&gt;linear&lt;/em&gt; code we can apply &lt;em&gt;mutations&lt;/em&gt; to &lt;em&gt;types&lt;/em&gt; as the program progresses.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;obj.property &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;obj satisfies string; &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// fails as 2 is not a string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;obj.property &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;obj satisfies string; &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// fails as 2 is not a string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This simple case is quite simple to implement. But problems occur when using functions. A huge experiment in Ezno is for functions to record &lt;em&gt;special properties&lt;/em&gt; not representable by just types. &lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=2iitje&quot;&gt;We can see this in the following example&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;setAt&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;at&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	obj[at] &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;debug_effects_rust&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(setAt)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;setAt&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;at&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	obj[at] &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;debug_effects_rust&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(setAt)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We will skip over a lot here but jumping straight into the deep end and the front of this experiment &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/specification/specification.md#array-push&quot;&gt;the specification has an example which shows the application of some of the &lt;code&gt;Array.prototype.push&lt;/code&gt; mutation information&lt;/a&gt;. This gives us more precise information on values after mutations.&lt;/p&gt;
&lt;p&gt;WW also account for mutations in &lt;code&gt;for ... in ...&lt;/code&gt; loop. Again glossing over a lot here, but the assignments in the loop get collected and when we call some functions which use this, we inspect the object that is &lt;code&gt;in&lt;/code&gt;&#39;d and we run each assignment for each (enumerable) property key in the object.&lt;/p&gt;
&lt;p&gt;In fact this is also how &lt;code&gt;Object.entries&lt;/code&gt;, &lt;code&gt;Object.values&lt;/code&gt; and &lt;code&gt;Object.assign&lt;/code&gt; work. We define them as&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;declare&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Object&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;keys&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { [&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; })&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;keys&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            keys.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(key);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; keys&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;values&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { [&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; })&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;values&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            values.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(on[key]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; values&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;entries&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { [&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; })&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;[&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;entries&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;[&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; on) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            entries.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;([key, on[key]]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; entries&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;declare&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Object&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;keys&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { [&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; })&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;keys&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            keys.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(key);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; keys&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;values&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { [&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; })&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;values&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            values.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(on[key]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; values&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;entries&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { [&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; })&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;[&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;entries&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;[&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; on) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            entries.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;([key, on[key]]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; entries&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and we get the following results (at least on ezno &lt;code&gt;0.0.22&lt;/code&gt;, it is broken in the latest Ezno and we seem to miss out on the first iteration. Hopefully I can find some time to track down what is broken here soon)&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/object-method-results.png&quot; alt=&quot;object-method-results&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This may seems like a lot of work but this mechanism has a lot of other benefits and I think it is the coolest part of Ezno. I will eventually share the whole system and some really interesting things I have discovered.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;complications-with-object.defineproperty&quot; tabindex=&quot;-1&quot;&gt;Complications with  &lt;code&gt;Object.defineProperty&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;These inferred side-effect things are cool. However for some things we can&#39;t use mutations based on JavaScript code, these being&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Internal APIs (aren&#39;t possible just using JS syntax)&lt;/li&gt;
&lt;li&gt;APIs that would be quite complex to write in terms of events (also don&#39;t make sense for all inputs). For example &lt;code&gt;Math.sin&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;This is similar with JavaScript runtimes. For certain things they use special native code for these functions rather than just JavaScript.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The function &lt;code&gt;Object.defineProperty&lt;/code&gt; has this property. It isn&#39;t possible to write an alternative for this function just using &lt;code&gt;[key]&lt;/code&gt; and &lt;code&gt;=&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So rather than giving this function a body and using the events it has a different behaviour for a constant function. When &lt;code&gt;Object.defineProperty&lt;/code&gt; is called, &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/16f7779b157dea4da2b618d8e192492a09d1acb9/checker/src/features/constant_functions.rs#L406-L528&quot;&gt;it instead runs this internal logic in &lt;code&gt;constant_functions.rs&lt;/code&gt;&lt;/a&gt;. It isn&#39;t perfect, but it does accept sensible usage of this API.&lt;/p&gt;
&lt;p&gt;Previously we saw that we needed a &lt;code&gt;readonly&lt;/code&gt; annotation this value. But we can do exactly the same in JavaScript&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=32i0ay&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/object-define-property.png&quot; alt=&quot;object-define-property&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;locking-objects-with-freeze%2C-seal-and-preventextensions&quot; tabindex=&quot;-1&quot;&gt;Locking objects with &lt;code&gt;freeze&lt;/code&gt;, &lt;code&gt;seal&lt;/code&gt; and &lt;code&gt;preventExtensions&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;The initial mapped type PR included basic support for &lt;code&gt;freeze&lt;/code&gt;. But thanks to an &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/213&quot;&gt;external PR&lt;/a&gt; the logic is now extended to cover &lt;code&gt;preventExtensions&lt;/code&gt; and&lt;code&gt;seal&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=27wr9e&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/object-seal.png&quot; alt=&quot;object-seal&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-current-representation-for-properties%3A-adding-publicity&quot; tabindex=&quot;-1&quot;&gt;The current representation for properties: adding &lt;code&gt;Publicity&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Over the course of this blog post we have built up the representation of properties. The final piece is that this key-value pair is a actually a triple including &lt;code&gt;Publicity&lt;/code&gt; (&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_properties&quot;&gt;public or private&lt;/a&gt;), &lt;code&gt;PropertyKey&lt;/code&gt; and &lt;code&gt;PropertyValue&lt;/code&gt;. (&lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/219&quot;&gt;However full private and public property checking is unfinished&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;They are stored in a array (&lt;code&gt;Vec&lt;/code&gt;), for example the type annotation &lt;code&gt;{ a: 0, b: 2 }&lt;/code&gt; is represented something similar to&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Publicity&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Public&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;a&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Publicity&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Public&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;b&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PropertyValue&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Publicity&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Public&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;a&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Publicity&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Public&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyKey&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;b&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PropertyValue&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As discussed the type checker in Ezno is mutation (technically fully side-effect) aware and dependent so traditional representing this as &lt;code&gt;obj = type with properties&lt;/code&gt; doesn&#39;t quite work. Instead we say &lt;code&gt;obj = *object 100*&lt;/code&gt; and then record properties onto each object for each context.&lt;/p&gt;
&lt;p&gt;This is because objects can have difference properties in different contexts. &lt;em&gt;There isn&#39;t a globally true list of properties for a object&lt;/em&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { property: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ctx.properties = { &amp;#39;obj&amp;#39;: [[&amp;quot;property&amp;quot;, { value: 1 }]] }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (condition) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	obj.property &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ctx.properties = { &amp;#39;obj&amp;#39;: [[&amp;quot;property&amp;quot;, { value: 1 }], [&amp;quot;property&amp;quot;, { value: 2 }]] }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// obj.property = 2 throughout here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;something&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// obj.property = 1 still here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ctx.properties = { &amp;#39;obj&amp;#39;: [[&amp;quot;property&amp;quot;, { value: 1 }]] }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { property: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ctx.properties = { &amp;#39;obj&amp;#39;: [[&amp;quot;property&amp;quot;, { value: 1 }]] }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (condition) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	obj.property &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ctx.properties = { &amp;#39;obj&amp;#39;: [[&amp;quot;property&amp;quot;, { value: 1 }], [&amp;quot;property&amp;quot;, { value: 2 }]] }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// obj.property = 2 throughout here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;something&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// obj.property = 1 still here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ctx.properties = { &amp;#39;obj&amp;#39;: [[&amp;quot;property&amp;quot;, { value: 1 }]] }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;The current system also enables interface merging. However not all types store their properties on the context. Thanks to a recent change, anonymous object type annotations store their properties actually on the type.&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The eagle eyed among you will notice that in the first branch, &lt;code&gt;obj&lt;/code&gt; has two properties named &lt;code&gt;property&lt;/code&gt;. I am still unsure whether appending rather than replacing is the best approach. It does mean that assigning a property doesn&#39;t have to check the rest and not-implemented at the moment but it means that LSP hover could instead only print up-to some assignment. This system is fine though as access accounts for this finding the first match when walking right-to-left.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;improvements-to-listing-types&quot; tabindex=&quot;-1&quot;&gt;Improvements to listing types&lt;/h3&gt;
&lt;p&gt;The PR also made some improvements for being able to get all properties on an object. Now &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/16f7779b157dea4da2b618d8e192492a09d1acb9/checker/src/types/properties/list.rs#L105&quot;&gt;number properties are sorted and added first&lt;/a&gt;, &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/16f7779b157dea4da2b618d8e192492a09d1acb9/checker/src/types/properties/list.rs#L43-L45&quot;&gt;the &lt;code&gt;enumerable&lt;/code&gt; property is checked&lt;/a&gt; and &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/16f7779b157dea4da2b618d8e192492a09d1acb9/checker/src/types/properties/access.rs#L67-L84&quot;&gt;properties with both &lt;code&gt;get&lt;/code&gt;ter and &lt;code&gt;set&lt;/code&gt;ter fixed&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Additionally &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/180&quot;&gt;thanks to an external PR&lt;/a&gt; added a while back, when a property is not find it gives alternatives using the Levenshtein algorithm on these keys.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/property-alternatives.png&quot; alt=&quot;property-alternatives&quot; /&gt;&lt;/p&gt;
&lt;h3 id=&quot;future-changes-to-properties-for-consideration&quot; tabindex=&quot;-1&quot;&gt;Future changes to properties for consideration&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;None of this adds anything. But there is still things that could be changed with regards to this representation of properties.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Separate out &lt;code&gt;PropertyValue::Configured&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;Maybe this could be held separately on the context&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Adding &lt;em&gt;metadata&lt;/em&gt; to properties
&lt;ul&gt;
&lt;li&gt;This is needed for documentation comments in the LSP&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Restructuring the &lt;code&gt;LocalInformation.properties&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;Maybe removing &lt;code&gt;PropertyValue::Optional&lt;/code&gt; for &lt;code&gt;{ a: string, b?: string } == { a: string } &amp;amp; ({ b: string } | {})&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Publicity&lt;/code&gt; item absorbed in &lt;code&gt;PropertyKey&lt;/code&gt; ?&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;p&gt;Hopefully you enjoyed this blog post! If you haven&#39;t seen yet there are recent blog posts on &lt;a href=&quot;https://kaleidawave.github.io/posts/experimental-types&quot;&gt;experimental types&lt;/a&gt; and a &lt;a href=&quot;https://kaleidawave.github.io/posts/sets-types-and-type-checking&quot;&gt;background on type theory&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Experimental types</title>
    <link href="https://kaleidawave.github.io/posts/experimental-types/"/>
    <updated>2024-11-13T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/experimental-types/</id>
    <summary>Extending the TypeScript type system with negation and refined number types</summary>
    <content xml:lang="en" type="html">&lt;p&gt;Over this summer, while working on increasing TypeScript compatibility in the checker and tackling more advanced type problems, I had an escapade with some experimental types! These types expand on what is currently representable in TypeScript. This blog post will introduce them, when they come about and things they catch.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;For those who haven&#39;t heard of it before, the &lt;a href=&quot;https://github.com/kaleidawave/ezno&quot;&gt;Ezno&lt;/a&gt; type checker is a work-in-progress but fast and correct TypeScript type checker and compiler with additional experiments.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;the-missing-operation&quot; tabindex=&quot;-1&quot;&gt;The missing operation&lt;/h3&gt;
&lt;p&gt;Set theory is based on three operations: unions, intersections and &lt;em&gt;one other&lt;/em&gt;. We can build a union of a type with &lt;code&gt;|&lt;/code&gt; and intersections with &lt;code&gt;&amp;amp;&lt;/code&gt; but this third operation is less common and does not exist in the TypeScript type system.&lt;/p&gt;
&lt;p&gt;This means that the types of some expressions are hard to represent. We can see this here&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (param &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(param)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//          ^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (param &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(param)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//          ^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we know that &lt;code&gt;param&lt;/code&gt; is a string (by the parameter type annotation) &lt;strong&gt;but we additionally know&lt;/strong&gt; from the conditional statement it is &lt;strong&gt;not&lt;/strong&gt; an empty string &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt; because of the condition (&lt;code&gt;param !== &amp;quot;&amp;quot;&lt;/code&gt;). While this state doesn&#39;t cause any type problems and treating as &lt;code&gt;string&lt;/code&gt; is mostly fine, it does miss out on information that it has a &lt;em&gt;negated member&lt;/em&gt;. For example if we only have the &lt;code&gt;string&lt;/code&gt; information, the type checker doesn&#39;t raise an disjoint error for the following equalities&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (param &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; param &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//     ^^^^^^^^^^^^ &amp;lt;- this equality is always **false** because `param !== &amp;quot;&amp;quot;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// or slightly more complex via control flow&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (param &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; param &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//     ^^^^^^^^^^^^ &amp;lt;- this equality is always false because `param !== &amp;quot;&amp;quot;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (param &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; param &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//     ^^^^^^^^^^^^ &amp;lt;- this equality is always **false** because `param !== &amp;quot;&amp;quot;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// or slightly more complex via control flow&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (param &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; param &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//     ^^^^^^^^^^^^ &amp;lt;- this equality is always false because `param !== &amp;quot;&amp;quot;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;While these examples are short and the cases are obvious, you can see how in longer functions with more conditions and other things going on these cases are get more difficult for a user to observe.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;More on reachability and narrowing in a future blog post!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 class=&quot;center&quot;&gt;&lt;p&gt;So we want &lt;strong&gt;a new kind of type&lt;/strong&gt; which can represent the &lt;em&gt;negation&lt;/em&gt; of some properties or members. This type is called the &lt;code&gt;Not&lt;/code&gt; type and transforms a single type.&lt;/p&gt;
&lt;/h3&gt;
&lt;h4 id=&quot;the-not-type&quot; tabindex=&quot;-1&quot;&gt;The &lt;code&gt;Not&lt;/code&gt; type&lt;/h4&gt;
&lt;p&gt;So we now want to construct a type which can wrap an existing type and &lt;em&gt;negate&lt;/em&gt; it.&lt;/p&gt;
&lt;p&gt;A simple way that avoids changing the &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/src/types/mod.rs&quot;&gt;checkers &lt;code&gt;Type&lt;/code&gt; declaration&lt;/a&gt; is to introduce a new &lt;em&gt;intrinsic type&lt;/em&gt;. &lt;a href=&quot;https://www.typescriptlang.org/docs/handbook/utility-types.html#intrinsic-string-manipulation-types&quot;&gt;TSC already has string intrinsic types&lt;/a&gt; (and &lt;code&gt;NoInfer&lt;/code&gt;). We can define another special internal type alias intrinsic called &lt;code&gt;Not&lt;/code&gt; that wraps another type using the type parameter, similar to how regular &lt;em&gt;generic&lt;/em&gt; type alias types work &lt;em&gt;(but without eager specialisation, because it is in its final form)&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Using a intrinsic type here&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Avoids new syntax&lt;/li&gt;
&lt;li&gt;Is consistent in implementation to other intrinsic types in the checker&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 class=&quot;center&quot;&gt;&lt;p&gt;With our new type at hand we can represent the type of our parameter &lt;strong&gt;inside&lt;/strong&gt; the condition to be &lt;code&gt;param: string &amp;amp; Not&amp;lt;&amp;quot;&amp;quot;&amp;gt;&lt;/code&gt;. (Here &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt; is the empty string).&lt;/p&gt;
&lt;/h3&gt;
&lt;h4 id=&quot;creating-a-negated-type-through-narrowing&quot; tabindex=&quot;-1&quot;&gt;Creating a negated type through narrowing&lt;/h4&gt;
&lt;p&gt;In the checker expressions in branching structures can refine types in a process known as narrowing.&lt;/p&gt;
&lt;p&gt;There will be more on narrowing in a future blog post but for now we can say that the function that produces &lt;em&gt;narrowed facts&lt;/em&gt; from a expression also takes a &lt;code&gt;negated&lt;/code&gt; parameter.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; string &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;--&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;narrow&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(negated: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, expression: &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; NarrowedFacts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; string &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;--&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;narrow&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(negated: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, expression: &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; NarrowedFacts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; string &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;--&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;narrow&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(negated: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, expression: &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; NarrowedFacts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; string &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;--&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;narrow&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(negated: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, expression: &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; NarrowedFacts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For the first case we say &lt;code&gt;x: string&lt;/code&gt;. In the second case where negated is true, when we produce the facts we wrap them all in &lt;code&gt;Not&lt;/code&gt;, so get &lt;code&gt;x: Not&amp;lt;string&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;For most unions (&lt;code&gt;1 | 2&lt;/code&gt;) we can actually filter the members and don&#39;t introduce a &lt;code&gt;Not&lt;/code&gt; type. We only introduce this for the &lt;em&gt;large&lt;/em&gt; unions such as &lt;code&gt;number&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt; etc. If you have any questions about narrowing that could be covered in that post, leave them in the comments below!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;exposing-negated-types-type-to-annotations&quot; tabindex=&quot;-1&quot;&gt;Exposing negated types type to annotations&lt;/h4&gt;
&lt;p&gt;While having it picked up by narrowing and the &lt;code&gt;!==&lt;/code&gt; operator is cool, I will also be generous and &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/9088496e28796fa0a4a8c938ee261c6611e695bb/checker/src/context/root.rs#L83&quot;&gt;add this special type to the root context&lt;/a&gt; for use in your programs.&lt;/p&gt;
&lt;p&gt;We will come onto how subtyping of this negated type works in a minute, but for now we can modify a functions parameter definition to force callers of our function to &lt;strong&gt;not&lt;/strong&gt; take zero as an argument.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;divide&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;numerator&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;denominator&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Not&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;) { &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;divide&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;numerator&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;denominator&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Not&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;) { &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=mhai&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/not-as-parameter.png&quot; alt=&quot;not-as-parameter&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;You can try this example out in the &lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=mhai&quot;&gt;online checker playground&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;subtyping-and-disjoint-ness-of-negated-types&quot; tabindex=&quot;-1&quot;&gt;Subtyping and disjoint-ness of negated types&lt;/h4&gt;
&lt;p&gt;So far everything seems quite straightforward: register our intrinsic type, map negated narrows and put it in root so you can reference and use it. So you might be expecting that the usage of it in the type system is where the complexity comes? But you would be wrong, the &lt;code&gt;Not&lt;/code&gt; mechanism can be entirely based on existing functionality.&lt;/p&gt;
&lt;p&gt;An example of the assignment case could be passing a &lt;code&gt;string&lt;/code&gt; argument to a parameter typed as &lt;code&gt;Not&amp;lt;number&amp;gt;&lt;/code&gt;. If you like set theory you might have guessed already, but &lt;strong&gt;subtyping a &lt;code&gt;Not&lt;/code&gt; type is based on &lt;a href=&quot;https://kaleidawave.github.io/posts/sets-types-and-type-checking/#disjoint-ness&quot;&gt;disjoint-ness&lt;/a&gt;!&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For string to be a subtype of &lt;code&gt;Not&amp;lt;number&amp;gt;&lt;/code&gt; (&lt;code&gt;string &amp;lt;: Not&amp;lt;number&amp;gt;&lt;/code&gt;) is for the &lt;code&gt;number&lt;/code&gt; and &lt;code&gt;string&lt;/code&gt; types to be disjoint! And this is true, there is element that satisfies the contracts of both &lt;strong&gt;string&lt;/strong&gt; and &lt;strong&gt;number&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/diagrams/types-not-venn-diagram.png&quot; alt=&quot;negation&quot; /&gt;&lt;/p&gt;
&lt;p&gt;And we already have a implementation of &lt;a href=&quot;https://kaleidawave.github.io/posts/experimental-types/(https://github.com/kaleidawave/ezno/blob/main/checker/src/types/disjoint.rs)&quot;&gt;disjoint checking&lt;/a&gt;, which is used for the equality operator &lt;code&gt;===&lt;/code&gt; etc.&lt;/p&gt;
&lt;p&gt;So we have covered subtyping, but lets get back to the first example&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (param &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; param &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//     ^^^^^^^^^^^^ &amp;lt;- this equality is always **false** because `param !== &amp;quot;&amp;quot;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (param &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; param &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//     ^^^^^^^^^^^^ &amp;lt;- this equality is always **false** because `param !== &amp;quot;&amp;quot;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we want to test whether &lt;code&gt;Not&amp;lt;&amp;quot;&amp;quot;&amp;gt;&lt;/code&gt; is disjoint with &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt;. And it turns out this is also a really simple operation, now in reverse: for &lt;code&gt;Not&amp;lt;&amp;quot;&amp;quot;&amp;gt;&lt;/code&gt; to be disjoint with &lt;code&gt;&amp;quot;&amp;quot;&lt;/code&gt; is for the empty string to be a subtype of the empty string (&lt;code&gt;&amp;quot;&amp;quot; &amp;lt;: &amp;quot;&amp;quot;&lt;/code&gt;) which is true as subtyping is a reflexive relation (&lt;code&gt;T = T =&amp;gt; subtype&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;As another example testing whether &lt;code&gt;Not&amp;lt;string&amp;gt;&lt;/code&gt; is disjoint with &lt;code&gt;&amp;quot;hello&amp;quot;&lt;/code&gt; is testing whether &lt;code&gt;&amp;quot;hello&amp;quot;&lt;/code&gt; is a subtype of &lt;code&gt;string&lt;/code&gt;. Thus if we have a strict equal operate check in TypeScript we know that &lt;code&gt;(x satisfies Not&amp;lt;string&amp;gt;) === &amp;quot;hello&amp;quot;&lt;/code&gt; is &lt;strong&gt;always going to return false&lt;/strong&gt; and we can emit this as a warning during our type checking procedure (technically a linting warning, based of type information).&lt;/p&gt;
&lt;h3 class=&quot;center&quot;&gt;&lt;p&gt;In summary: when left subtyping &lt;code&gt;Not&lt;/code&gt; then we test disjoint and when disjoint with &lt;code&gt;Not&lt;/code&gt; we test subtyping.&lt;/p&gt;
&lt;/h3&gt;
&lt;p&gt;Some other details&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When &lt;code&gt;Not&lt;/code&gt; is the super-type, it is never a subtype.&lt;/li&gt;
&lt;li&gt;In many usages &lt;code&gt;Not&lt;/code&gt; drops down to being a &lt;code&gt;any&lt;/code&gt; type&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The really important thing is through set theory to be assignable to &lt;code&gt;Not&amp;lt;0&amp;gt;&lt;/code&gt; implies that it is disjoint from &lt;code&gt;0&lt;/code&gt;&lt;/strong&gt;. It is not simply denying the &lt;code&gt;0&lt;/code&gt; type but all types that have &lt;code&gt;0&lt;/code&gt; as a member&lt;/li&gt;
&lt;li&gt;Most types are of the form &lt;code&gt;T &amp;amp; Not&amp;lt;U&amp;gt;&lt;/code&gt; where we have properties of &lt;code&gt;T&lt;/code&gt; but we want to remove the properties of &lt;code&gt;U&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;Because this type reuses the intrinsic system and the fact that subtyping and disjoint are already implemented. This addition is a &amp;lt;100 LOC addition.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/src/types/disjoint.rs&quot;&gt;See the disjoint function here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Disjoint is currently not implemented for functions and objects. &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/212&quot;&gt;You can read issue if you want to tackle it!&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;aside%3A-not-vs-exclude&quot; tabindex=&quot;-1&quot;&gt;Aside: &lt;code&gt;Not&lt;/code&gt; vs &lt;code&gt;Exclude&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;&lt;code&gt;Exclude&lt;/code&gt; can be used to &lt;em&gt;negate&lt;/em&gt; members. However it only works for unions and so only simple cases. The &lt;code&gt;Not&lt;/code&gt; type is much more complex and can &lt;em&gt;pick&lt;/em&gt; out constant from larger types.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;From a language purity standpoint &lt;em&gt;intrinsic&lt;/em&gt;s are not great. Common utilities like this I think are fine though as long as the internal type list doesn&#39;t break 100 it should be fine.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;You can see the negated types feature request in TSC &lt;a href=&quot;https://github.com/microsoft/TypeScript/issues/4196&quot;&gt;here&lt;/a&gt; which would be similar to the &lt;code&gt;Not&lt;/code&gt; type described above.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;numeric-restrictions&quot; tabindex=&quot;-1&quot;&gt;Numeric restrictions&lt;/h3&gt;
&lt;p&gt;With the new negated types, we have &lt;code&gt;Not&amp;lt;0&amp;gt;&lt;/code&gt; and &lt;code&gt;Not&amp;lt;NaN&amp;gt;&lt;/code&gt;, which can be helpful in restricting APIs to deal which can help when doing math without the crazy-ness of floating point mathematics and with the &lt;code&gt;x !== 7&lt;/code&gt;, the &lt;code&gt;Not&amp;lt;7&amp;gt;&lt;/code&gt; type can help catch disjoint errors &lt;strong&gt;based on single values&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;However, there is still some common cases involving numbers where we could have more accurate types. For example we know that the result of a &lt;code&gt;Math.sin&lt;/code&gt; call will never return a &lt;code&gt;2&lt;/code&gt; as the range is between &lt;code&gt;-1&lt;/code&gt; to &lt;code&gt;1&lt;/code&gt; (unfortunately JS does not support the &lt;svg style=&quot;vertical-align: -0.043ex;&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;1.633ex&quot; height=&quot;1.631ex&quot; role=&quot;img&quot; focusable=&quot;false&quot; viewBox=&quot;0 -702 722 721&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;defs&gt;&lt;path id=&quot;MJX-2-TEX-D-2102&quot; d=&quot;M684 131Q684 125 672 109T633 71T573 29T489 -5T386 -19Q330 -19 276 -3T174 46T91 134T44 261Q39 283 39 341T44 421Q66 538 143 611T341 699Q344 699 364 700T395 701Q449 698 503 677T585 655Q603 655 611 662T620 678T625 694T639 702Q650 702 657 690V481L653 474Q640 467 628 472Q624 476 618 496T595 541Q562 587 507 625T390 663H381Q337 663 299 625Q212 547 212 336Q212 249 233 179Q274 30 405 30Q533 30 641 130Q658 147 666 147Q671 147 677 143T684 131ZM250 625Q264 643 261 643Q238 635 214 620T161 579T110 510T79 414Q74 384 74 341T79 268Q89 213 113 169T164 101T217 61T260 39L277 34Q270 41 264 48Q199 111 181 254Q178 281 178 344T181 434Q200 559 250 625ZM621 565V625Q617 623 613 623Q603 619 590 619H575L588 605Q608 583 610 579L621 565Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;scale(1,-1)&quot;&gt;&lt;g data-mml-node=&quot;math&quot;&gt;&lt;g data-mml-node=&quot;TeXAtom&quot; data-mjx-texclass=&quot;ORD&quot;&gt;&lt;g data-mml-node=&quot;mi&quot;&gt;&lt;use data-c=&quot;2102&quot; xlink:href=&quot;#MJX-2-TEX-D-2102&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt; complex datatype).&lt;/p&gt;
&lt;p&gt;So similar to the &lt;code&gt;Not&lt;/code&gt; addition we can add some more behaviour here, so without further ado we have ranged types.&lt;/p&gt;
&lt;h4 id=&quot;implementation&quot; tabindex=&quot;-1&quot;&gt;Implementation&lt;/h4&gt;
&lt;p&gt;Similar to negated types we can add this with intrinsic. We implement this with two new intrinsic types &lt;code&gt;LessThan&lt;/code&gt; and &lt;code&gt;GreaterThan&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Unlike &lt;code&gt;Not&lt;/code&gt;, these intrinsic have a bit more involved implementation that can&#39;t reuse much. When subtyping we check that the argument as a range fits inside the parameter type, for disjoint we check that they don&#39;t overlap as ranges. Unfortunately this is quite manual.&lt;/p&gt;
&lt;h4 id=&quot;narrowing-numbers&quot; tabindex=&quot;-1&quot;&gt;Narrowing numbers&lt;/h4&gt;
&lt;p&gt;We can extend the narrowing implementation to also handle cases from inequalities.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (param &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// param.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (param &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// param.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=2rvxtu&quot;&gt;And in the block we have &lt;code&gt;param: LessThan&amp;lt;10&amp;gt;&lt;/code&gt;&lt;/a&gt; !!!&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;More on narrowing in the future. Hiding a lot of the complexities of &lt;code&gt;&amp;lt;=&lt;/code&gt; and building up number types that have the form &lt;code&gt;LessThan&amp;lt;floor&amp;gt; &amp;amp; GreaterThan&amp;lt;ceiling&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;annotations-and-ranges&quot; tabindex=&quot;-1&quot;&gt;Annotations and ranges&lt;/h4&gt;
&lt;p&gt;Similar to &lt;code&gt;Not&lt;/code&gt; we will &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/16f7779b157dea4da2b618d8e192492a09d1acb9/checker/src/context/root.rs#L79-L80&quot;&gt;add &lt;code&gt;LessThan&lt;/code&gt; and &lt;code&gt;GreaterThan&lt;/code&gt; to the root&lt;/a&gt;. From these primitives we can define ranges as intersections of these types and we can make endpoints inclusive with unions.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;GreaterThanOrEqual&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;GreaterThan&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExclusiveRange&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;F&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;C&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;GreaterThan&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;F&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;LessThan&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;C&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;GreaterThanOrEqual&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;GreaterThan&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExclusiveRange&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;F&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;C&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;GreaterThan&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;F&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;LessThan&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;C&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;These are defined in the standard &lt;code&gt;lib.d.ts&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;The implementation for them is pretty nasty. It is nicer to deal with them in terms of ranges (for example checking disjoint-ness) but it is an abstraction that breaks down.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And we can actually use this type in the standard library, for example &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/8ce921e39c3d4e947063f206347b2932cee456ec/checker/definitions/simple.d.ts#L230&quot;&gt;&lt;code&gt;Math.sin&lt;/code&gt; returns a &lt;code&gt;InclusiveRange&amp;lt;-1, 1&amp;gt;&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;what-you-can-do-with-them&quot; tabindex=&quot;-1&quot;&gt;What you can do with them&lt;/h3&gt;
&lt;p&gt;We can do some pretty simple things with them for annotations. For example requiring that positive numbers in places.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=28j85e&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/positive-numbers.png&quot; alt=&quot;positive-numbers&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The cool things come from narrowing and operations. For example we can catch equality as they have an implementation for disjoint-ness.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=2siewy&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/range-disjoint.png&quot; alt=&quot;range-disjoint&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We can add more logic to our inequalities testing whether a range is always above or below.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=27wr2i&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/greater-than-always-true.png&quot; alt=&quot;greater-than-always-true&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Also transitivity kind of works (this is with the bounds not being known numbers)&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=2rvxu2&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/number-intrinsic-transitivity.png&quot; alt=&quot;number-intrinsic-transitivity&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;multipleof&quot; tabindex=&quot;-1&quot;&gt;&lt;code&gt;MultipleOf&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Similar to &lt;code&gt;LessThan&lt;/code&gt; and &lt;code&gt;GreaterThan&lt;/code&gt;, &lt;code&gt;MultipleOf&lt;/code&gt; is another new intrinsic number type that can be used to narrow down on the value of numbers.&lt;/p&gt;
&lt;p&gt;We again expose this through a type annotation such as &lt;code&gt;MultipleOf&amp;lt;5&amp;gt;&lt;/code&gt; and also through narrowing with &lt;code&gt;x % 5 === 0&lt;/code&gt;. I won&#39;t go through the details of it all here.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=28j85m&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/multiple-of-narrowing.png&quot; alt=&quot;multiple-of-narrowing&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;integers&quot; tabindex=&quot;-1&quot;&gt;Integers&lt;/h3&gt;
&lt;p&gt;Integers can be created by &lt;code&gt;MultipleOf&amp;lt;1&amp;gt;&lt;/code&gt;. This is because these number intrinsic are based on the &lt;code&gt;number&lt;/code&gt; type which at runtime is floating point number.&lt;/p&gt;
&lt;h4 id=&quot;integers-with-arrays-%2F-strings%3F&quot; tabindex=&quot;-1&quot;&gt;Integers with arrays / strings?&lt;/h4&gt;
&lt;p&gt;My intuition is that this can help with array/string indexing. For example we know that if a value is in &lt;code&gt;0 &amp;amp; LessThan&amp;lt;this.length&amp;gt; &amp;amp; Integer&lt;/code&gt;, we know it is not &lt;code&gt;undefined&lt;/code&gt;. This can help for indexing an array (or a string) in &lt;code&gt;for (let i = 0&lt;/code&gt;  loops (which do come up). There is some problems with holey arrays though and so I haven&#39;t done added anything around this.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;(although holey arrays seem user driven with &lt;code&gt;delete&lt;/code&gt;, I don&#39;t think they can come from external APIs)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;There are a lot of things we could extract from floats. It could assit with WASM generation where there exists whole numbers. But investigating all of these takes time and is a bit out of scope for the moment.&lt;/p&gt;
&lt;h3 id=&quot;more-restrictions-with-the-literal-type&quot; tabindex=&quot;-1&quot;&gt;More restrictions with the &lt;code&gt;Literal&lt;/code&gt; type&lt;/h3&gt;
&lt;p&gt;Another intrinsic type which I added ages ago is &lt;code&gt;Literal&lt;/code&gt;. This constrains the user to only be able to write known constants to this value.&lt;/p&gt;
&lt;p&gt;This can help with some things. For example you can &lt;em&gt;lock&lt;/em&gt; down &lt;code&gt;fetch&lt;/code&gt; calls to only use fixed URLs, custom element registration etc.&lt;/p&gt;
&lt;p&gt;Unfortunately, this doesn&#39;t add any safety... but it could be some using in adding rules into the language. Here JavaScript will always let you create a property under the key of the current weather in the UK.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Reflect&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(obj, &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;https://uk-weather.api&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;then&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;resp&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; resp.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Property always exists&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(obj.cloudy)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// okay sometimes this&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(obj.sunny)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Reflect&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(obj, &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;https://uk-weather.api&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;then&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;resp&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; resp.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Property always exists&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(obj.cloudy)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// okay sometimes this&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(obj.sunny)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;but we can create a better way using &lt;code&gt;Literal&amp;lt;...&amp;gt;&lt;/code&gt; types&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ReflectingOnReflect&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;better_set&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Literal&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;object&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;property&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Literal&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;any&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  ) { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ... &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ReflectingOnReflect&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;better_set&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Literal&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;object&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;property&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Literal&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;any&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  ) { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ... &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=2siex6&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/literal-restriction.png&quot; alt=&quot;literal-restriction&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;testing-and-feedback&quot; tabindex=&quot;-1&quot;&gt;Testing and feedback&lt;/h3&gt;
&lt;p&gt;Hopefully you found something interesting. All of this is open source, you can play with them in the playground and if you find any bugs with the new experimental items, post them on the issue tracker.&lt;/p&gt;
&lt;p&gt;And if you have found anything difficult to represent as types, that is still not covered by these new types, let me know in the comments below!&lt;/p&gt;
&lt;h3 id=&quot;direction-of-the-project&quot; tabindex=&quot;-1&quot;&gt;Direction of the project&lt;/h3&gt;
&lt;p&gt;While this stuff is fun, there is probably a number of you asking whether you can begin using this is projects. The unfortunate answer is that the &lt;strong&gt;ezno-checker is not currently usable on projects because of the lack of many TSC features or partially implemented features&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The checker has been crawling along slowly, passing more and more specification tests and working on more complex parts. I now somewhat confident in the foundation and that many of TSC&#39;s features have been somewhat reimplemented. You will see in the next two blog posts that cover mapped types and narrowing respectively.&lt;/p&gt;
&lt;p&gt;While these experiments like this are interesting, they don&#39;t necessarily work perfectly under all the edge cases. In some cases a number of the features have been relegated behind the &lt;code&gt;--advanced-numbers&lt;/code&gt; flag.&lt;/p&gt;
&lt;p&gt;The biggest experiment in the checker has been side-effects recording and replaying. There have been some huge progress with respect to that, most of which I have not currently shared (but maybe soon). A lot of that stuff is currently very delicate and so I think the next steps will be to put that behind a flag. Once that is mostly out of the way for default, the actually usability can be attempted.&lt;/p&gt;
&lt;p&gt;Currently allocation of resources is a bit of a constraint, but that only affects the timelines of these things and not the achievability. However there is still more to share and I have a blog post on mapped types and one on narrowing (on more than just number types) that should be ready for publishing soon!&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;This blog post was sent out to sponsors early. As well as supporting the development of the project you also get early access on information on the project and access to the LSP! As well as monetary contributions, you can also contribute code. There are some &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues?q=sort%3Aupdated-desc+is%3Aissue+is%3Aopen+label%3Agood-first-issue&quot;&gt;good-first-issues&lt;/a&gt; and &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues?q=sort%3Aupdated-desc+is%3Aissue+label%3Agood-first-issue+is%3Aclosed&quot;&gt;many have already been completed&lt;/a&gt; by some awesome contributors!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Sets, types and type checking</title>
    <link href="https://kaleidawave.github.io/posts/sets-types-and-type-checking/"/>
    <updated>2024-10-30T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/sets-types-and-type-checking/</id>
    <summary>My currently understanding of types</summary>
    <content xml:lang="en" type="html">&lt;p&gt;In the process of building &lt;a href=&quot;https://github.com/kaleidawave/ezno&quot;&gt;a type-checker&lt;/a&gt; I have learnt a lot of the details about the theory of types and sets. With all this information I thought I would unpack all the details I have encountered along the way.&lt;/p&gt;
&lt;p&gt;This first part of this post explains why type-checking exists and what the abstraction of types enables. After some justification for type-theory, we delve deep into what types are and details on the common constructions. In the finale we will put the definitions to work and explain the implementation of type checking including operations on types.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;While not many people are building type checkers, a background of the implementation can help with being more effective when using (or dealing) with a type checker.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;I have a few upcoming posts on more advanced and niche type features. So I thought I would put together this post that lays the foundations so that I can refer to it the more advanced things. It has been quite fun recapping on some of the parts I have built along the way.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Some of this is relevant to TypeScript (and other structural systems) but there are parts that are apply generally to programming languages of all kinds of implementation of &amp;quot;typing&amp;quot;. And in some of the wall of text there is real life analogies, interesting diagrams and some &lt;strong&gt;interactive&lt;/strong&gt; gizmos!&lt;/p&gt;
&lt;p&gt;This is my interpretation of type theory based on the things I have worked with or built. &lt;strong&gt;Similar to the type checker, it is not complete and this post may evolve&lt;/strong&gt;. If you think I have not covered anything in this general post or alternatively have any cool resources on type theory, you can share them to the comment section at the bottom of this post!&lt;/p&gt;
&lt;h2 id=&quot;types-provide-information&quot; tabindex=&quot;-1&quot;&gt;Types provide information&lt;/h2&gt;
&lt;p&gt;Before delving into the details, I thought it would be good to justify why the theory exists for all those asking the point of type theory?&lt;/p&gt;
&lt;p&gt;The simplest way to put it is that what: types provide information about the structure of expressions, what parts of the programs take as input and what parts produces as output.&lt;/p&gt;
&lt;h3 id=&quot;information-for-errors-in-invalid-programs&quot; tabindex=&quot;-1&quot;&gt;Information for errors in invalid programs&lt;/h3&gt;
&lt;p&gt;The main association of &amp;quot;types&amp;quot; is in type-checking. Once the program types have been resolved, each individual type can be compared between other types and usage of the value to check that the program is sound.&lt;/p&gt;
&lt;p&gt;For example here we find that a number is being multiplied by a string. In this example multiplication on strings is not defined and so we have a problem with the program. Information about this type can either be surfaced at runtime or like the below ahead-of-time. Either way, denoting the type of an expression has helped find an issue in the declaration of this program.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/diagrams/type-checking-playground.png&quot; alt=&quot;type checking playground&quot; /&gt;&lt;/p&gt;
&lt;h3 id=&quot;information-for-build-optimisations&quot; tabindex=&quot;-1&quot;&gt;Information for build optimisations&lt;/h3&gt;
&lt;p&gt;I will not go too much into it here, but type information is useful for making decisions for the program to run with less overhead. For example in C, giving type information about &lt;em&gt;numbers instructs more optimal registers to use in the CPU&lt;/em&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;There are slightly more esoteric behaviours such as mutable aliases in Rust. But will not go too much into optimisations here and focus on checking aspects of types.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;information-for-the-programmer&quot; tabindex=&quot;-1&quot;&gt;Information for the programmer&lt;/h3&gt;
&lt;p&gt;Humans like characterising things and types provide a way to do that within programs and code. Not everything can benefit from the additional syntax, but for data based problems, writing out the types before the logic can help better structure the program and understand what needs to be accomplished. When coming back to code we can look for the key data structures and from there see how the methods connect up. Things like adding return types to function can help understand what the function generally does without having to delve into the full definition.&lt;/p&gt;
&lt;p&gt;Types also help when understanding the unfamiliar. Whether that be a standard library or an external library, providing type information can help to see what some. For example the Rust &lt;a href=&quot;https://doc.rust-lang.org/stable/std/&quot;&gt;std.rs&lt;/a&gt; (and &lt;a href=&quot;https://docs.rs/ezno-parser/latest/ezno_parser/&quot;&gt;docs.rs for a individual libraries&lt;/a&gt;) is a encyclopaedia of structs, enums and traits which all come under the umbrella of type information.&lt;/p&gt;
&lt;p&gt;Additionally types help with making changes to code. If we change a function, then we can see how that change affects code that it was relying on it. Additionally while changelogs are helpful, this abstraction is much more mechanised for upgrading 3rd party libraries.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I won&#39;t go fully into the ergonomics of types, but I think it is good to state that types &lt;em&gt;are not just for the machine&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Types are not the only components for the abstraction program, other properties such as intermediate representation (IR), control flow graphs, concrete and abstract-syntax-trees etc parts all with for different things for parts of program synthesis (program synthesis = a machine understanding what a program does)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;what-is-a-type%3F&quot; tabindex=&quot;-1&quot;&gt;What is a type?&lt;/h2&gt;
&lt;p&gt;Types describe data. Data represents things, properties, maps from data to other data, information about the relation of things. Types allow us to categorise data and this discernment and grouping allows  reasoning.&lt;/p&gt;
&lt;p&gt;This categorisation is done based on properties. Here I use the word &lt;strong&gt;property&lt;/strong&gt; in the abstract sense, something measurable of the data, some way about the data works in regards to the rest of the system. (&lt;a href=&quot;https://en.wikipedia.org/wiki/Property_(programming)&quot;&gt;A sort of extension to fields and data members as in programming languages&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Some real world properties could be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Is red&lt;/li&gt;
&lt;li&gt;Puts out fires&lt;/li&gt;
&lt;li&gt;Is a fire-truck&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Each of these properties is tailored to the language. For example some languages have &amp;quot;symbols&amp;quot; which are basically unique values for a program. We could define a type that requires the exact symbol. Similarly other languages have the concept of &lt;code&gt;asynchronous&lt;/code&gt; functions, this property could be encoded into the features of a type. In Rust we could have a function which requires the inputs to be of type &lt;code&gt;&amp;amp;&#39;static str&lt;/code&gt; which are string slices valid throughout the lifetime of a program. We could also have restrictions such as the type implementing &lt;a href=&quot;https://doc.rust-lang.org/stable/std/fmt/trait.Display.html&quot;&gt;Display&lt;/a&gt; meaning that it has a can be printed to a user.&lt;/p&gt;
&lt;p&gt;This encoding of properties as a types provides the information to reason about what data is throughout the lifetime of a program and so in the the cases show above can help catch issues and optimise programs ahead of time.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Types are slightly different to sets in which they are based on construction rather than predicates. Construction refers to building something given some input. We have some data we can form a member of the type via some constructor. I will write about the differences in a future post. But for the most part sets can be considered equivalent to types, with the same rules and uses.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;members&quot; tabindex=&quot;-1&quot;&gt;Members&lt;/h3&gt;
&lt;p&gt;In the world there exist entities that fall under these properties&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Tomatoes, the YouTube logo and 🌉 are all red&lt;/li&gt;
&lt;li&gt;Carbon dioxide and 🧯 can put out fires&lt;/li&gt;
&lt;li&gt;🚒 is a fire truck&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To say that a value satisfies the property is often know as a typing judgement and we often write it as colon. For example &lt;code&gt;⊢ 🚒: fire truck&lt;/code&gt;, or in the sense of programming language &lt;code&gt;⊢ 5 : number&lt;/code&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Note you will see the &lt;code&gt;:&lt;/code&gt; come up a lot in type theory&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;facts-about-members&quot; tabindex=&quot;-1&quot;&gt;Facts about members&lt;/h4&gt;
&lt;p&gt;Like sets, types can be by description have an infinite number of distinct members. However when it comes to programs on deterministic Turing machines (computers) there are only a finite amount of numbers that can be represented due to limitations of memory. Benefiting from exponential combinations, while finite it turns out even with 8 bytes of memory you can still &lt;a href=&quot;https://doc.rust-lang.org/std/primitive.u64.html#associatedconstant.MAX&quot;&gt;cover a very large amount of numbers&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;When encoding these sort of types we could treat them as collections of the individual members. However, storing the members of &lt;code&gt;u64&lt;/code&gt; in some list would result in &lt;a href=&quot;https://www.wolframalpha.com/input?i=2%5E64+*+8+bytes+as+terabytes&quot;&gt;&lt;code&gt;147 000 000 terabytes&lt;/code&gt;&lt;/a&gt; of data and individually I can&#39;t begin to count the CPU years it would take to iterate through all &lt;svg style=&quot;vertical-align: 0;&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;2.919ex&quot; height=&quot;1.904ex&quot; role=&quot;img&quot; focusable=&quot;false&quot; viewBox=&quot;0 -841.7 1290.1 841.7&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;defs&gt;&lt;path id=&quot;MJX-10-TEX-N-32&quot; d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-10-TEX-N-36&quot; d=&quot;M42 313Q42 476 123 571T303 666Q372 666 402 630T432 550Q432 525 418 510T379 495Q356 495 341 509T326 548Q326 592 373 601Q351 623 311 626Q240 626 194 566Q147 500 147 364L148 360Q153 366 156 373Q197 433 263 433H267Q313 433 348 414Q372 400 396 374T435 317Q456 268 456 210V192Q456 169 451 149Q440 90 387 34T253 -22Q225 -22 199 -14T143 16T92 75T56 172T42 313ZM257 397Q227 397 205 380T171 335T154 278T148 216Q148 133 160 97T198 39Q222 21 251 21Q302 21 329 59Q342 77 347 104T352 209Q352 289 347 316T329 361Q302 397 257 397Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-10-TEX-N-34&quot; d=&quot;M462 0Q444 3 333 3Q217 3 199 0H190V46H221Q241 46 248 46T265 48T279 53T286 61Q287 63 287 115V165H28V211L179 442Q332 674 334 675Q336 677 355 677H373L379 671V211H471V165H379V114Q379 73 379 66T385 54Q393 47 442 46H471V0H462ZM293 211V545L74 212L183 211H293Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;scale(1,-1)&quot;&gt;&lt;g data-mml-node=&quot;math&quot;&gt;&lt;g data-mml-node=&quot;msup&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;32&quot; xlink:href=&quot;#MJX-10-TEX-N-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;TeXAtom&quot; transform=&quot;translate(533,363) scale(0.707)&quot; data-mjx-texclass=&quot;ORD&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;36&quot; xlink:href=&quot;#MJX-10-TEX-N-36&quot;&gt;&lt;/use&gt;&lt;use data-c=&quot;34&quot; xlink:href=&quot;#MJX-10-TEX-N-34&quot; transform=&quot;translate(500,0)&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt; members of the data and comparing that each entry is valid for the program. So instead for types like this it is easier to represent &lt;code&gt;u64&lt;/code&gt; as a number type that is unsigned (no negative values, zeroed out bytes is the number zero) and is 64 bits wide. With this information it covers all members and we can more efficiently reason about the value, rather than querying each entry.&lt;/p&gt;
&lt;p&gt;With members, we have a implication from a valid judgement. If we have that &lt;code&gt;x = y&lt;/code&gt; and that &lt;code&gt;x: number&lt;/code&gt; then we can conclude that &lt;code&gt;y&lt;/code&gt; is a number. This is generally a property you want to uphold when defining equality. The equality operator should be testing the all properties are equal and thus we can say they have equal types.&lt;/p&gt;
&lt;p&gt;Additionally a random last fact for members: It is harder to find members for types which have more properties (and so in general there are less members for types with more properties).&lt;/p&gt;
&lt;h3 id=&quot;fundamental-types%3A-any-and-never&quot; tabindex=&quot;-1&quot;&gt;Fundamental types: &lt;code&gt;any&lt;/code&gt; and &lt;code&gt;never&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Two of the most fundamental types are &lt;code&gt;any&lt;/code&gt; and &lt;code&gt;never&lt;/code&gt;. These are polar opposites of each other.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;any&lt;/code&gt; can be considered as a type which doesn&#39;t have a single required property. We can say a fire truck, a spoon or the string &lt;code&gt;&amp;quot;Hello World&amp;quot;&lt;/code&gt; is an element of &lt;code&gt;any&lt;/code&gt; thing because there are no properties to satisfy. (If it helps this is a case of the &lt;a href=&quot;https://en.wikipedia.org/wiki/Vacuous_truth&quot;&gt;vacuous truth&lt;/a&gt; with respect to the number of properties to satisfies being vacuous). Therefore &lt;code&gt;any&lt;/code&gt; contains every value you can construct.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;any&lt;/code&gt; exists in TypeScript &lt;strong&gt;but has slightly different behaviour in some cases&lt;/strong&gt; (explained later). But it is not just a property of the dynamically typed languages, Rust also has an &lt;a href=&quot;https://doc.rust-lang.org/std/any/trait.Any.html&quot;&gt;any type&lt;/a&gt; which works slightly differently but is used for general data. There also exists &lt;code&gt;unknown&lt;/code&gt; which is &lt;code&gt;any&lt;/code&gt; without the strange subtype behavior.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;code&gt;never&lt;/code&gt; on the other hand has all the possible constructed properties. To be an item of never is to be in London and on the moon and a single colour and be blue and and green and purple. Because it requires every property there will exist two properties that are mutually exclusive. (this will be covered later). You cannot be a single colour and blue and green at the same time. &lt;em&gt;&lt;em&gt;Thus there is no constructable&lt;/em&gt; item that satisfies &lt;code&gt;never&lt;/code&gt;&lt;/em&gt;*. Thus we can say that the collection of items that satisfies never is empty.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;never&lt;/code&gt; can be used to represent places where functions never exit. For example in an infinite loop or something that throws an exception. It exists in TypeScript under &lt;code&gt;never&lt;/code&gt; and &lt;a href=&quot;https://doc.rust-lang.org/std/primitive.never.html&quot;&gt;&lt;em&gt;sort of&lt;/em&gt; in Rust&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;As will be explained later these two types have very important positions in the hierarchy of types&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I don&#39;t think &lt;code&gt;never&lt;/code&gt; is a good name. Maybe &lt;code&gt;impossible&lt;/code&gt; or &lt;code&gt;CannotExist&lt;/code&gt; is alternative better names for thinking about this type. We can reason that it has no members as if ask for something &lt;code&gt;impossible&lt;/code&gt;, then you are stuck. You can&#39;t pass &lt;code&gt;5&lt;/code&gt;, or a &lt;code&gt;&amp;quot;Hello World&amp;quot;&lt;/code&gt; or a &lt;code&gt;Boat&lt;/code&gt; &lt;em&gt;as they all exist&lt;/em&gt;.&lt;/p&gt;
&lt;h2 id=&quot;conjugations-of-types&quot; tabindex=&quot;-1&quot;&gt;Conjugations of types&lt;/h2&gt;
&lt;p&gt;There are two forms of binary conjugations of types and their properties. Binary here meaning that there are two types being joined. This results in its own type as so we can form a recursive definition of a type.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;For implementing the definition of this type: you can represent both of these as a vector or a binary tree of other types.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;and-types-(set-intersections)&quot; tabindex=&quot;-1&quot;&gt;And types (set intersections)&lt;/h3&gt;
&lt;p&gt;An &lt;code&gt;and / &amp;amp;&lt;/code&gt; type represents a intersection of two types. This is equivalent to saying that members of this type satisfy properties of &lt;strong&gt;both&lt;/strong&gt; the LHS and RHS. For example we can define a rainforest as having a continuous tree canopy and high humidity. For an item to be considered to a rainforest it must both satisfies the properties of having a continuous tree canopy &lt;strong&gt;AND&lt;/strong&gt; having high humidity. If either of this conditions is unmet then it cannot be considered under this type.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RainForest&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ContinousTreeCanopy&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;HighHumidity&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RainForest&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ContinousTreeCanopy&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;HighHumidity&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/diagrams/types-venn-diagram.png&quot; alt=&quot;intersection venn diagram&quot; /&gt;&lt;/p&gt;
&lt;p&gt;A definition of this type will be unique, however and types are symmetric. &lt;code&gt;A &amp;amp; B&lt;/code&gt; is equivalent type to &lt;code&gt;B &amp;amp; A&lt;/code&gt;.&lt;/p&gt;
&lt;h4 id=&quot;javascript-objects-are-why-we-have-intersection-types&quot; tabindex=&quot;-1&quot;&gt;JavaScript objects are why we have intersection types&lt;/h4&gt;
&lt;p&gt;You may be thinking what are the use cases for an intersection type?&lt;/p&gt;
&lt;p&gt;The first thing to know if that in TypeScript, object type annotations only specify their required properties and can allow members to have more than specified. For example &lt;code&gt;⊢ { a: &amp;quot;hi&amp;quot;, b: 4 }: { a: string }&lt;/code&gt;. Just their definition doesn&#39;t require there to be an exact amount of properties.&lt;/p&gt;
&lt;p&gt;Many languages don&#39;t have intersection type. Often the intersection types in set land are represented as products/tuples (fixed sized lists) in other languages.&lt;/p&gt;
&lt;p&gt;For example &lt;code&gt;[{ a: &amp;quot;hi&amp;quot; }, { b: 4 }]&lt;/code&gt; has the equivalent amount of data as &lt;code&gt;{ a: &amp;quot;hi&amp;quot;, b: 4 }&lt;/code&gt; (it even retains the order, which is a strange property of JS objects), but we want our type system to not allow &lt;code&gt;.push&lt;/code&gt; on this item. &lt;strong&gt;Hence we have intersections and don&#39;t resort to tuples to maintain the same semantics as JavaScript&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;With the intersection type we can build up objects &lt;code&gt;{ a: string } &amp;amp; { b: number } = { a: string, b: number }&lt;/code&gt;.  While&lt;/p&gt;
&lt;p&gt;#insert the colour SVG thing here&lt;/p&gt;
&lt;p&gt;Also most of the time, they are stored in flat representation. For example while we can represent a structure definition as an intersection of single property objects, grouping them together just makes the implementation easier, especially in other languages that have to consider type layout which requires knowledge of the adjacent properties is required. &lt;strong&gt;So instead and types are used to extend existing types&lt;/strong&gt;. If we have existing &lt;code&gt;Type&lt;/code&gt; we can extend it with more properties with the and type operator &lt;code&gt;type Extended = Type &amp;amp; { property: string }&lt;/code&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In some languages this can be considered as a refinement type. We have a base type but we adjoin extra required properties on-top of the LHS.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;reducing-intersection-types&quot; tabindex=&quot;-1&quot;&gt;Reducing intersection types&lt;/h4&gt;
&lt;p&gt;Intersection types have a &lt;em&gt;diagonal identity&lt;/em&gt;. &lt;code&gt;A &amp;amp; A = A&lt;/code&gt;, so if we try to build an intersection with the same type we can just return the initial result. Additionally &lt;code&gt;never &amp;amp; A&lt;/code&gt; is always &lt;code&gt;never&lt;/code&gt;. While there might be members for &lt;code&gt;A&lt;/code&gt;, we don&#39;t have any members for &lt;code&gt;never&lt;/code&gt; and so the nothing exists in &lt;code&gt;never &amp;amp; A&lt;/code&gt; and therefore it is equivalent to &lt;code&gt;never&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Additionally there are some other reductions we can do (these include operations that will be covered later). The first is that if A is a subtype of B we can consider the &lt;strong&gt;smaller&lt;/strong&gt; type (subtype): &lt;code&gt;A &amp;amp; B = A&lt;/code&gt;. For example &lt;code&gt;4 &amp;amp; number = 4&lt;/code&gt;. Additionally if type A is disjoint from B we can consider the result to be &lt;code&gt;never&lt;/code&gt;: &lt;code&gt;A &amp;amp; B = never&lt;/code&gt;. For example &lt;code&gt;number &amp;amp; string = never&lt;/code&gt;.&lt;/p&gt;
&lt;h5 id=&quot;why-the-intersection-with-any-is-always-any&quot; tabindex=&quot;-1&quot;&gt;Why the intersection with &lt;code&gt;any&lt;/code&gt; is always &lt;code&gt;any&lt;/code&gt;&lt;/h5&gt;
&lt;p&gt;An important point here is when &lt;code&gt;any &amp;amp; X&lt;/code&gt; is considered. From a set perspective it should say that &lt;code&gt;any&lt;/code&gt; is always the super type (larger than &lt;code&gt;X&lt;/code&gt;) so &lt;code&gt;any &amp;amp; X&lt;/code&gt; is always &lt;code&gt;X&lt;/code&gt; . However TSC has slightly different meaning for &lt;code&gt;any&lt;/code&gt; in places and actually considers it a subtype as well (covered later). Therefore for TypeScript &lt;code&gt;any &amp;amp; X&lt;/code&gt; is actually &lt;code&gt;any&lt;/code&gt;. I am not sure if the subtyping reuse is why this is the result, or whether it is specified specially here but the general take that in cases of any, the result is mostly &lt;code&gt;any&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;or-types-(set-unions-or-sum-types)&quot; tabindex=&quot;-1&quot;&gt;Or types (set unions or sum types)&lt;/h3&gt;
&lt;p&gt;An &lt;code&gt;or / |&lt;/code&gt; type represents a union of two types. This means that this value can either have the properties of the left type &lt;strong&gt;OR&lt;/strong&gt; the right type. For example we can define a train as either a &lt;code&gt;CargoTrain&lt;/code&gt; or a &lt;code&gt;PassengerTrain&lt;/code&gt;, which we can represent as &lt;code&gt;type Trait = CargoTrain | PassengerTrain&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Note that this is not exclusive or relation. We can define sum type such as &lt;code&gt;blue | wet&lt;/code&gt; then the sea &lt;code&gt;blue&lt;/code&gt; so it is considered an entry, it isn&#39;t necessarily to check the &lt;code&gt;wet&lt;/code&gt; property. Normally most sum types are between disjoint properties so this is not an issue.&lt;/p&gt;
&lt;p&gt;Similar to intersection types, this can be recursive relation &lt;code&gt;A | B | C | D&lt;/code&gt;. We can consider this as a list of a binary tree &lt;code&gt;((A | B) | C) | D&lt;/code&gt;. This can be useful for things as &lt;code&gt;type TrafficColor = &amp;quot;red&amp;quot; | &amp;quot;amber&amp;quot; | &amp;quot;green&amp;quot;&lt;/code&gt; (at least in the UK).&lt;/p&gt;
&lt;h4 id=&quot;equivalence-rules&quot; tabindex=&quot;-1&quot;&gt;Equivalence rules&lt;/h4&gt;
&lt;p&gt;Similar to and types there are many equivalent representations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;They are symmetric &lt;code&gt;A | B = B | A&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Satisfy a &lt;em&gt;diagonal identity&lt;/em&gt; &lt;code&gt;A | A = A&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Additionally, &lt;code&gt;never&lt;/code&gt; types in unions can be removed/collapsed. Aka &lt;em&gt;Is it going to rain today or does it never rain in England&lt;/em&gt; is equivalent to &lt;em&gt;Is it going to rain today&lt;/em&gt; (and so is collapsed down to the left, because the case on the right is never held). Therefore constructing types we can just keep the never cases &lt;code&gt;A | never = A&lt;/code&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;You can think of &lt;code&gt;any&lt;/code&gt; as being a union of all possible types&lt;/strong&gt;. Using the symmetric to rearrange and the diagonal identity we can therefore see &lt;code&gt;A | any = any&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Additionally like intersection types, we can reduce it based off of disjoint and subtyping. If two members are &lt;strong&gt;not disjoint&lt;/strong&gt; we can pick the larger type. For example &lt;code&gt;string | &amp;quot;hi&amp;quot;&lt;/code&gt; can be considered as the larger type &lt;code&gt;string&lt;/code&gt;. (The interesting point is that intersections we can pick the &lt;strong&gt;smaller&lt;/strong&gt; type (subtype) whereas with union types we pick the &lt;strong&gt;larger&lt;/strong&gt; type (super type))&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Ezno does not do eager reduction or test subtypes when. I have found that at some point causes more problems than it solves just for minor visual clean up and potential to do slightly less subtypes per usage. Especially when you consider the combinatoric scale of checks when comparing all the items large unions.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;tagged-vs-untagged-sum-types&quot; tabindex=&quot;-1&quot;&gt;Tagged vs untagged sum types&lt;/h4&gt;
&lt;p&gt;Rust has both untagged unions with &lt;a href=&quot;https://doc.rust-lang.org/reference/items/unions.html&quot;&gt;&lt;code&gt;union&lt;/code&gt;&lt;/a&gt; and tagged with &lt;a href=&quot;https://doc.rust-lang.org/reference/items/enumerations.html&quot;&gt;&lt;code&gt;enum&lt;/code&gt;&lt;/a&gt;. This tag is called the &lt;code&gt;discriminant&lt;/code&gt; and retrieved with the titular &lt;a href=&quot;https://doc.rust-lang.org/stable/std/mem/fn.discriminant.html&quot;&gt;discriminant&lt;/a&gt; function (&lt;a href=&quot;https://play.rust-lang.org/?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=f422553e049465b220d48b486f2ff514&quot;&gt;which extracts tag data under-the-hood&lt;/a&gt;). This value / tag is unique between each defined variant.&lt;/p&gt;
&lt;p&gt;In JavaScript each variant (before optimisations) has a tag. You can consider it &lt;em&gt;globally tagged&lt;/em&gt;. This isn&#39;t exposed through memory but operations like &lt;code&gt;typeof&lt;/code&gt; and &lt;code&gt;instanceof&lt;/code&gt; are based reading this tag (&lt;em&gt;some of the time&lt;/em&gt;). In this crude example we can consider the first four bits of a value to include its tag. For example booleans are &lt;code&gt;0&lt;/code&gt;, numbers are &lt;code&gt;1&lt;/code&gt;, strings are &lt;code&gt;2&lt;/code&gt; and objects are something different all together maybe referencing something else in memory that contains there shape.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0b0000_0000&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0b0000_0001&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0b0001_0101&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0b0010_1010&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0b1010_0000&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0b0000_0000&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0b0000_0001&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0b0001_0101&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0b0010_1010&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0b1010_0000&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;If you are interested in learning more about this I would recommend posts on V8 about how it represents objects.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;nullability-and-error-handling&quot; tabindex=&quot;-1&quot;&gt;Nullability and error handling&lt;/h4&gt;
&lt;p&gt;One of the more common usages of sum types is for representing some data which can be missing. For example we can represent the colour of a ships sail as &lt;code&gt;Color | null&lt;/code&gt; as some boats do not have a sail.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;declare&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getSailColor&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;boat&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Boat&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Color&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;null&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;declare&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getSailColor&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;boat&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Boat&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Color&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;null&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;In Rust we have &lt;a href=&quot;https://doc.rust-lang.org/stable/std/option/enum.Option.html&quot;&gt;&lt;code&gt;Option&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/a&gt;, which is equivalent to &lt;code&gt;T | null&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;We can expand on the &lt;code&gt;null&lt;/code&gt; variant with an type which has more information about the why the first value was not returned. For example we can expand on the above function with more information&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;declare&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getSailColor&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;boat&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Boat&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Color&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;Boat has no sail&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;boat_kind&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;BoatKind&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;declare&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getSailColor&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;boat&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Boat&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Color&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;Boat has no sail&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;boat_kind&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;BoatKind&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;In Rust we have &lt;a href=&quot;https://doc.rust-lang.org/stable/std/result/enum.Result.html&quot;&gt;&lt;code&gt;Result&amp;lt;T, E&amp;gt;&lt;/code&gt;&lt;/a&gt;, which is equivalent to &lt;code&gt;T | E&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;(I think) In Golang the is no definition of a sum of types. Instead you can use the fact that every value is adjoined with a &lt;code&gt;null&lt;/code&gt; member. Instead to represent something like the error type above can use pairs of these values to represent sum types instead.&lt;/p&gt;
&lt;h3 id=&quot;combinations-of-conjugations&quot; tabindex=&quot;-1&quot;&gt;Combinations of conjugations&lt;/h3&gt;
&lt;p&gt;Note that both of these are subject follow the roots of boolean algebra. Each operations is are symmetric and importantly they distribute.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;(A | B) &amp;amp; C = (A &amp;amp; C) | (B &amp;amp; C)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;In word terms: an apple or banana that is large is the same as a banana that is large or an apple that is large.&lt;/p&gt;
&lt;h4 id=&quot;all-types-are-unions-of-intersections&quot; tabindex=&quot;-1&quot;&gt;All types are unions of intersections&lt;/h4&gt;
&lt;p&gt;You can think of as all types as being a union of some intersection. These are cases of necessary conditions. The &lt;code&gt;{ a: string, b: number } | null&lt;/code&gt; can be thought of as two cases &lt;code&gt;*object*&lt;/code&gt; or &lt;code&gt;null&lt;/code&gt;. In the first case there are two necessary conditions that &lt;code&gt;obj.a: string&lt;/code&gt; &lt;strong&gt;and&lt;/strong&gt; &lt;code&gt;obj.b: number&lt;/code&gt;. In a sense the reduction above is forming the minimum cases.&lt;/p&gt;
&lt;h2 id=&quot;parametrised-types&quot; tabindex=&quot;-1&quot;&gt;Parametrised types&lt;/h2&gt;
&lt;p&gt;Often called generics and used to model structures that are dependent on some type: parameter can be added to various definitions to specifying insertion of types at certain places. This can be useful for providing templates for types.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;These are sometimes considered PI types or &amp;quot;big and types&amp;quot;, which I might cover more in a future blog post.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;code&gt;Array&lt;/code&gt; is an example of a type that has some relation to an inner type or works over many types. While we could consider the items of an array to just be &lt;code&gt;any&lt;/code&gt; we can refine this type by detailing the types of individual members.&lt;/p&gt;
&lt;p&gt;One way would be to define a type for each kind of an array.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;StringArray&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;NumberArray&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;StringArray&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;NumberArray&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This has the problem that we now to duplicate the definition and each time are tweaking the same fields. It also means that if we create a new type such as &lt;code&gt;Boat&lt;/code&gt;, the user has to create a whole new specific definition for &lt;code&gt;Array&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Therefore we use generics to denote a sort of template for our general type&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;We will see later how, but we can create equivalent definitions above by instantiating the above with &lt;code&gt;type StringArray = Array&amp;lt;string&amp;gt;; type NumberArray = Array&amp;lt;number&amp;gt;;&lt;/code&gt;. We can also solve the problem when introducing new types as we can get our array of boats with &lt;code&gt;Array&amp;lt;boat&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;We can add parameters via chevron notation &lt;code&gt;&amp;lt;T&amp;gt;&lt;/code&gt;. They can be directly added structures like &lt;code&gt;interface&lt;/code&gt; in TypeScript and on &lt;code&gt;struct&lt;/code&gt; and &lt;code&gt;enum&lt;/code&gt; in Rust. We can also add them for any type using type aliases. Our &lt;code&gt;Option&lt;/code&gt; type from Rust we can represent as &lt;code&gt;type Option&amp;lt;T&amp;gt; = T | null&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;These are often used for general types, things that a bit &lt;em&gt;meta&lt;/em&gt; that represent &lt;strong&gt;modifications&lt;/strong&gt; of things in nature rather than existing in &lt;strong&gt;nature&lt;/strong&gt; themselves. For example &lt;code&gt;Array&amp;lt;T&amp;gt;&lt;/code&gt; for a list of values with an unspecified length, or &lt;code&gt;Set&amp;lt;T&amp;gt;&lt;/code&gt; for the same without order specified and with the condition that values are uniquely added, or &lt;code&gt;Map&amp;lt;K, V&amp;gt;&lt;/code&gt; for associations for data. (the latter two can be defined in terms of &lt;code&gt;Array&amp;lt;T&amp;gt;&lt;/code&gt;)&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Often use &lt;code&gt;T&lt;/code&gt; as the first letter in type. From there additional go up the alphabet into &lt;code&gt;U&lt;/code&gt; etc. For things like &lt;code&gt;Map&lt;/code&gt; we use &lt;code&gt;K&lt;/code&gt; and &lt;code&gt;V&lt;/code&gt; for &lt;code&gt;Key&lt;/code&gt; and &lt;code&gt;Value&lt;/code&gt; respectively. Sometimes &lt;code&gt;I&lt;/code&gt; for item. But we normally have the convention of being a single character and like most type names for the first character to be uppercase.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;parameter-types&quot; tabindex=&quot;-1&quot;&gt;Parameter types&lt;/h3&gt;
&lt;p&gt;The parameters that we can give to our types are types themselves. They have names we can reference in annotations, used the intersection and union types shown above and also in everything following this.&lt;/p&gt;
&lt;p&gt;Generally these types extend &lt;code&gt;any&lt;/code&gt;. We can change that though with the &lt;code&gt;T extends Type&lt;/code&gt; syntax in TypeScript and with &lt;code&gt;T: SomeTrait&lt;/code&gt; in Rust. For example for our &lt;code&gt;Set&amp;lt;T&amp;gt;&lt;/code&gt; definition we can require that the parameter &lt;code&gt;T&lt;/code&gt; implements equality and maybe a hash operation (heuristic for equality) for the set to be to valid.&lt;/p&gt;
&lt;h3 id=&quot;partially-applied-generics&quot; tabindex=&quot;-1&quot;&gt;Partially applied generics&lt;/h3&gt;
&lt;p&gt;With regards to parametric types we can instantiate them with type arguments. For example we can have an array but expand to that the elements of the array are strings with the &lt;code&gt;Array&amp;lt;string&amp;gt;&lt;/code&gt; syntax.&lt;/p&gt;
&lt;p&gt;This &lt;code&gt;string&lt;/code&gt; tells us that if we have a expression of this array type then getting an element of it will return a &lt;code&gt;string&lt;/code&gt;. It tells us more though, for example &lt;code&gt;push&lt;/code&gt; must take strings as inputs for our array to still all be strings. it tells us that the functions passed to &lt;code&gt;.map&lt;/code&gt;, &lt;code&gt;.every&lt;/code&gt;, &lt;code&gt;.some&lt;/code&gt; must all be defined for strings so that they can be evaluated against the elements.&lt;/p&gt;
&lt;p&gt;This point is important: &lt;strong&gt;a type parameter may be used many places including nested in other types such as parameters for functions on methods&lt;/strong&gt;. Therefore we need to handle these generics carefully as not create lots of instantiations based one argument.&lt;/p&gt;
&lt;h4 id=&quot;lazy-lookup-of-generic-types&quot; tabindex=&quot;-1&quot;&gt;Lazy lookup of generic types&lt;/h4&gt;
&lt;p&gt;In the above example we looked at the &lt;code&gt;Array&lt;/code&gt; type, I have revealed a few more fields on the type to show how type parameters can be appear multiple times in difference places.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;mapped&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;mapped&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When we have a reference such as  &lt;code&gt;Array&amp;lt;string&amp;gt;&lt;/code&gt; we need to produce an internal representation of this specific type of &lt;code&gt;Array&lt;/code&gt;. One method would be to take the &lt;code&gt;Array&lt;/code&gt; definition and walking the structure, copying out each member substituting any references for &lt;code&gt;T&lt;/code&gt; with &lt;code&gt;string&lt;/code&gt;. Such would result in the following.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	[item: string]: number;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(t: string);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(mapped: (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	[item: string]: number;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(t: string);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(mapped: (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;However&lt;/strong&gt;, we can speed up this step and instead form a  &lt;em&gt;&lt;code&gt;PartiallyAppliedGenerics&lt;/code&gt;&lt;/em&gt; item. &lt;a href=&quot;https://docs.rs/ezno-checker/latest/ezno_checker/types/struct.PartiallyAppliedGenerics.html&quot;&gt;&lt;code&gt;PartiallyAppliedGenerics&lt;/code&gt;&lt;/a&gt; is a pair of a type (with generic parameters such as our original unspecified &lt;code&gt;Array&lt;/code&gt;) and a &lt;code&gt;Map&lt;/code&gt; with arguments (&lt;code&gt;Vec&amp;lt;(TypeId, TypeId)&amp;gt;&lt;/code&gt;). So &lt;code&gt;Array&amp;lt;string&amp;gt;&lt;/code&gt; becomes &lt;code&gt;PartiallyAppliedGenerics { on: Array, arguments: { T = string } }&lt;/code&gt;. This form is a lot more efficient as we just need to create a single wrapper &lt;code&gt;Type&lt;/code&gt; and don&#39;t have to inspect or copy any of the internal structure when we instantiate a specific version of an &lt;code&gt;Array&lt;/code&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;(aside from checking that it has matching parametrised and type arguments match &lt;code&gt;extends&lt;/code&gt; clauses).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;I think &lt;em&gt;partially applied&lt;/em&gt; is the correct term, we &lt;em&gt;fix&lt;/em&gt; some types but don&#39;t fully evaluate everything.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This however means that using this type is a little bit more difficult to use. We can&#39;t just access a field in the regular field as it hasn&#39;t be specialised with the arguments.&lt;/p&gt;
&lt;p&gt;So now when accessing information (a property, calling a function etc) we lazily compute it by unwrapping the pairing. Arguments is collected in a table like structure called &lt;code&gt;GenericChain&lt;/code&gt; and the left side is run unfolded. If a generic is found, the table is queried (in the checker I am building it is with the method &lt;code&gt;.get_argument_covaraint&lt;/code&gt;) and only the &lt;em&gt;closest&lt;/em&gt; item needs to be substituted.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;PartiallyAppliedGenerics&lt;/code&gt; wraps things like generic interfaces, methods which inherit parent terms and anonymous objects. Note that type aliases is not in this list as in TypeScript for type aliases (&lt;code&gt;type AliasName&amp;lt;T&amp;gt; = ...&lt;/code&gt;) instantiating them eagerly substitutes them into the RHS, rather than leaving them as &lt;code&gt;AliasName&amp;lt;Argument&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;All type arguments on structures are considered restrictions for usage, so in type terms &amp;quot;covariant&amp;quot;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;This mechanism is reused for another feature around closed over variables. But that is for another post.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;special-root-types&quot; tabindex=&quot;-1&quot;&gt;Special root types&lt;/h2&gt;
&lt;h3 id=&quot;products-of-types-%2F-tuples-%2F-pairs&quot; tabindex=&quot;-1&quot;&gt;Products of types / tuples / pairs&lt;/h3&gt;
&lt;p&gt;We can form concatenations of types with products. For example we can accept a number and string for a function with a tuple. This is normally defined by a comma separated list within either parenthesis &lt;code&gt;()&lt;/code&gt; in Rust or &lt;code&gt;[]&lt;/code&gt; brackets in TypeScript.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]) {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]) {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Products are different to type intersections as explained above for JavaScript objects. They do have equivalent properties though, but that is a for a future post.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Tuples can be heterogenous (of different types) whereas arrays normally are homogeneous with the same type (up to sum types). In TypeScript &lt;code&gt;Array&lt;/code&gt; can heterogenous and so the tuples are not so much a completely different type but instead a special kind of array with more properties for the exact length and exact types at exact indices.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In set theory, this is known as &lt;a href=&quot;https://en.wikipedia.org/wiki/Cartesian_product&quot;&gt;Cartesian product&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;objects%2Fstructs-are-a-special-product-types&quot; tabindex=&quot;-1&quot;&gt;Objects/structs are a special product types&lt;/h4&gt;
&lt;p&gt;With tuples we normally access items by their zero-based index. In the above example if we want the number data passed we retrieve it with &lt;code&gt;a[0]&lt;/code&gt; (or in Rust &lt;code&gt;a.0&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Structs and objects extend this idea by referring to these indexes by string keys (instead of numbers). In Rust&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	first&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; number,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	second&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	first&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; number,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	second&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;is equivalent to the &lt;code&gt;(number, string)&lt;/code&gt; type but it has the additional compile time metadata which allows us to refer to the fields with more natural names (you can see how this especially helps when we have fields of the same type).&lt;/p&gt;
&lt;p&gt;In TypeScript, it inherits that objects information exists at runtime and so the objects are slightly more complex. They also allow addition of properties that were not present at the time of declaration so the types become slightly more complex.&lt;/p&gt;
&lt;h3 id=&quot;functions&quot; tabindex=&quot;-1&quot;&gt;Functions&lt;/h3&gt;
&lt;p&gt;Functions are a fundamental type in the theory. They represent transformations between lists of values to other values.&lt;/p&gt;
&lt;p&gt;Function types abstract the code definition of the expression function and primarily focus on what the inputs and outputs are.&lt;/p&gt;
&lt;p&gt;A function is defined as a sequence of parameters, which have required types. The types for inputs is called its codomain and the result of applying/calling the function is the domain.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Parameters are the variables. Arguments are the values passed to the function at the call-site &lt;a href=&quot;https://rust-lang.github.io/rust-clippy/master/index.html#/too_many_arguments&quot;&gt;Ahem&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;generic-parameters&quot; tabindex=&quot;-1&quot;&gt;Generic parameters&lt;/h4&gt;
&lt;p&gt;Similar to generic types, functions can also be parameterised with generics. Sometimes these values can come from above (such as the &lt;code&gt;T&lt;/code&gt; in &lt;code&gt;Array.prototype.map&lt;/code&gt;). Some are local and are set at the call-site. In later parts we will see how these come to take a value and how they affect the result. But for now these are considered on the same level as parameters with a fixed type.&lt;/p&gt;
&lt;p&gt;There are however some special kind of parameters which make things a little bit trickier.&lt;/p&gt;
&lt;h4 id=&quot;default-arguments&quot; tabindex=&quot;-1&quot;&gt;Default arguments&lt;/h4&gt;
&lt;p&gt;Default arguments are values used in place of an argument missing&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// 1 + 2 = 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// 1 + 1 = 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// 1 + 2 = 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// 1 + 1 = 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is equivalent to after some de-sugaring&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;b_before_&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;undefined&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; b_before &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;??&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// 1 + 2 = 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// 1 + 1 = 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;b_before_&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;undefined&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; b_before &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;??&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// 1 + 2 = 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// 1 + 1 = 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;For reasons it is simpler to write the internals in terms of default arguments inline with language and to not apply this transformation. But you can see from this rewriting how it functionally works.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Note that the parameter changes type here. Despite the annotation, the resulting function parameter type is union-ed with &lt;code&gt;undefined&lt;/code&gt; which is the value it has in JavaScript when an argument is not passed&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;variadic-arguments&quot; tabindex=&quot;-1&quot;&gt;Variadic arguments&lt;/h4&gt;
&lt;p&gt;Rest/spread/variadic parameters is the fact that at a call site it can take a non-fixed amount of arguments such that the later are collected in a collection type like an array&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getLastArgument&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;at&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getLastArgument&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getLastArgument&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getLastArgument&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;at&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getLastArgument&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getLastArgument&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is equivalent to after some de-sugaring&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getLastArgument&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;at&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getLastArgument&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;([&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getLastArgument&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;([&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getLastArgument&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;at&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getLastArgument&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;([&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getLastArgument&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;([&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Similar to default arguments and especially because of the call site transform for a list this again does not apply this transformation and instead this &lt;em&gt;property&lt;/em&gt; is encoded into the function type.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;multiple-parameters-and-currying&quot; tabindex=&quot;-1&quot;&gt;Multiple parameters and currying&lt;/h4&gt;
&lt;p&gt;We can consider it under the currying to transform&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Repeating myself again. It is closer to the language to treat the parameters as a list. While finding more canonical representations can help simplify cases. Here we want to preserve a form closer to the syntactical representation as it helps in printing and calling. In a language such as Lean the forms are equivalent (the latter is desugared into the former).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Currying is named after the great &lt;a href=&quot;https://en.wikipedia.org/wiki/Haskell_Curry&quot;&gt;Haskell Curry&lt;/a&gt; a renowned logician. &lt;a href=&quot;https://en.wikipedia.org/wiki/Curry&quot;&gt;Curry&lt;/a&gt; is also great too.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;free-variables-and-closures&quot; tabindex=&quot;-1&quot;&gt;Free variables and closures&lt;/h4&gt;
&lt;p&gt;Sometimes a function can use reference something outside of its inner scope. When a variable is used above it is considered &amp;quot;free&amp;quot; as it is not bound by a parameter.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Difficult situations can arise when these can be mutated&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; b;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;b &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// 7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; b;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;b &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// 7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Closures are the level above free variables. It is where a function is returned that uses a free variable in the above scope.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;closure&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; () {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;++&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;closure&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; () {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;++&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Closures are hard as they implicitly store state. Unlike objects we don&#39;t construct a definition for what this data is like. It is sort handled implicitly build from the context. Closures have problems in lifetime based languages and so that is why the &lt;code&gt;move&lt;/code&gt; keyword exists in Rust.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Free_variables_and_bound_variables&quot;&gt;I think free-variables is the correct terminology&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;I have a further work on closures but will skip over for now.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;other-functional-properties&quot; tabindex=&quot;-1&quot;&gt;Other functional properties&lt;/h4&gt;
&lt;p&gt;Async functions can be considered to return their result as a &lt;code&gt;Promise&lt;/code&gt; (in TypeScript) or a &lt;code&gt;Future&lt;/code&gt; in Rust. These are considered as just modifications to their return type without much else effect.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Okay enough of the complications added by functions, back to type theory&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;conditional-types&quot; tabindex=&quot;-1&quot;&gt;Conditional types&lt;/h3&gt;
&lt;p&gt;We can define types (such as this return type for a function) whose properties depend on a condition&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;is string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;not string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { .. }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;is string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;not string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { .. }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here the type is &lt;code&gt;T extends string ? &amp;quot;is string&amp;quot; : &amp;quot;not string&amp;quot;&lt;/code&gt; with the condition &lt;code&gt;T extends string&lt;/code&gt; (which is a typing judgement slightly abused as a predicate here).&lt;/p&gt;
&lt;p&gt;As we will see later, when we call this function we substitute the return type. In this case we evaluate the judgement &lt;code&gt;extends string&lt;/code&gt; against our resolved value for &lt;code&gt;T&lt;/code&gt;. For the condition we can resolve one of the branches or both if this proposition is not resolved discretely into either &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This type is a union type with a little bit more information of what the result is. If we drop the conditional information it can be treated as &lt;code&gt;&amp;quot;is string&amp;quot; | &amp;quot;not string&amp;quot;&lt;/code&gt; in many cases.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In fact sometimes &lt;code&gt;A | B&lt;/code&gt; can be thought of as &lt;code&gt;*free condition* ? A : B&lt;/code&gt;, where the condition is unknown and unresolvable inside the system.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Sometimes, when using this type we might want to carry the condition data forward. If we index the first character here (with &lt;code&gt;item[0]&lt;/code&gt;) we can result with the more informed &lt;code&gt;T extends string ? &amp;quot;i&amp;quot; : &amp;quot;n&amp;quot;&lt;/code&gt; (rather than the weaker &lt;code&gt;&amp;quot;i&amp;quot; | &amp;quot;n&amp;quot;&lt;/code&gt;). This can sometimes better narrowing.&lt;/p&gt;
&lt;h3 id=&quot;implied-conditions-with-example-in-rust&quot; tabindex=&quot;-1&quot;&gt;Implied conditions with example in Rust&lt;/h3&gt;
&lt;p&gt;Rust does not have conditional types. You can imitate this with generic associate types but not in the same way as you have to have implementations for each possible input type. It is not possible to cover all the types like in TypeScript because of colliding implementations with &lt;code&gt;impl&lt;/code&gt;. Even with &lt;code&gt;#![feature(negative_bounds)]&lt;/code&gt; &lt;a href=&quot;https://play.rust-lang.org/?version=nightly&amp;amp;mode=debug&amp;amp;edition=2021&amp;amp;gist=2ea33373e65671f1621a0d91099866ad&quot;&gt;it does not seem possible&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&quot;conditional-types-distribute-across-their-condition&quot; tabindex=&quot;-1&quot;&gt;Conditional types distribute across their condition&lt;/h4&gt;
&lt;p&gt;An important thing is that for conditional types, if there condition is a sum type, then it is distributed.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;MyConditional&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;B&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;C&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Immediately interpreted as&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;MyConditional&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;C&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;B&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;C&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;MyConditional&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;B&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;C&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Immediately interpreted as&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;MyConditional&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;C&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;B&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;C&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;This is an immediate transformation and &lt;strong&gt;not an equivalent type&lt;/strong&gt;. This is also applied during generic substitution&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;This distribution added (I think) enables some fancy filtering of types. In the future I will show another way that this is possible.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;You can use the undistributed version by wrapping the two sides in unit tuples. &lt;code&gt;[A | B] extends [Type] ? X : Y&lt;/code&gt;;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;type-hierarchy&quot; tabindex=&quot;-1&quot;&gt;Type hierarchy&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/diagrams/types-hierarchy-diagram.png&quot; alt=&quot;hierarchy of types&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;color: #cceff1;&quot;&gt;1 ∎&lt;/span&gt; &lt;code&gt;any&lt;/code&gt; contains everything below it. &lt;span style=&quot;color: #bbbaeb;&quot;&gt;2 ∎&lt;/span&gt; here is where type classes (called traits in Rust which I think is a good name) exist. They are big unions of nominal types. &lt;span style=&quot;color: #c2acd8;&quot;&gt;3 ∎&lt;/span&gt; is where smaller unions exist which are useful for representing data up of &lt;span style=&quot;color: #d4a6dc;&quot;&gt;4 ∎&lt;/span&gt; nominal types. Boolean takes two to build its union. But &lt;code&gt;number&lt;/code&gt; (which is normally a 64-bit floating point number has &lt;svg style=&quot;vertical-align: 0;&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;2.919ex&quot; height=&quot;1.904ex&quot; role=&quot;img&quot; focusable=&quot;false&quot; viewBox=&quot;0 -841.7 1290.1 841.7&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;defs&gt;&lt;path id=&quot;MJX-11-TEX-N-32&quot; d=&quot;M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-11-TEX-N-36&quot; d=&quot;M42 313Q42 476 123 571T303 666Q372 666 402 630T432 550Q432 525 418 510T379 495Q356 495 341 509T326 548Q326 592 373 601Q351 623 311 626Q240 626 194 566Q147 500 147 364L148 360Q153 366 156 373Q197 433 263 433H267Q313 433 348 414Q372 400 396 374T435 317Q456 268 456 210V192Q456 169 451 149Q440 90 387 34T253 -22Q225 -22 199 -14T143 16T92 75T56 172T42 313ZM257 397Q227 397 205 380T171 335T154 278T148 216Q148 133 160 97T198 39Q222 21 251 21Q302 21 329 59Q342 77 347 104T352 209Q352 289 347 316T329 361Q302 397 257 397Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-11-TEX-N-34&quot; d=&quot;M462 0Q444 3 333 3Q217 3 199 0H190V46H221Q241 46 248 46T265 48T279 53T286 61Q287 63 287 115V165H28V211L179 442Q332 674 334 675Q336 677 355 677H373L379 671V211H471V165H379V114Q379 73 379 66T385 54Q393 47 442 46H471V0H462ZM293 211V545L74 212L183 211H293Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;scale(1,-1)&quot;&gt;&lt;g data-mml-node=&quot;math&quot;&gt;&lt;g data-mml-node=&quot;msup&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;32&quot; xlink:href=&quot;#MJX-11-TEX-N-32&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;TeXAtom&quot; transform=&quot;translate(533,363) scale(0.707)&quot; data-mjx-texclass=&quot;ORD&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;36&quot; xlink:href=&quot;#MJX-11-TEX-N-36&quot;&gt;&lt;/use&gt;&lt;use data-c=&quot;34&quot; xlink:href=&quot;#MJX-11-TEX-N-34&quot; transform=&quot;translate(500,0)&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt; members in the union). Exact object types could be considered here. &lt;span style=&quot;color: #eda2dd;&quot;&gt;5 ∎&lt;/span&gt; is useful for tags and small amounts of types. &lt;span style=&quot;color: #f3b4a0;&quot;&gt;6 ∎&lt;/span&gt; is dependent types. we know all the information about them and there is one entry. &lt;span style=&quot;color: #fad3a4;&quot;&gt; 7 ∎&lt;/span&gt; the &lt;code&gt;never&lt;/code&gt; type. Can be considered as an intersection as anything on the row above&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I haven&#39;t included functions, generics or some of the other previously seen types but just the basics to see how this lattice sort of representation holds&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;operations-on-types&quot; tabindex=&quot;-1&quot;&gt;Operations on types&lt;/h2&gt;
&lt;h3 id=&quot;subtyping&quot; tabindex=&quot;-1&quot;&gt;Subtyping&lt;/h3&gt;
&lt;p&gt;Subtyping around set types is basically asking this question:&lt;/p&gt;
&lt;p&gt;Does this set fit into this other set?&lt;/p&gt;
&lt;h4 id=&quot;when-and-why-subtyping&quot; tabindex=&quot;-1&quot;&gt;When and why subtyping&lt;/h4&gt;
&lt;p&gt;Before asking how to do subtyping we need to ask when it is done and why it is required. The following is a function with a parameter with type &lt;code&gt;number&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;addOne&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;addOne&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A call to this function is only valid when it is valid to &lt;strong&gt;substitute&lt;/strong&gt;/swap the arguments for parameters.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;parameter&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//   		  ^^^^^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//            parameter&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;argument&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//    ^^^^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//    argument&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;parameter&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//   		  ^^^^^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//            parameter&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;argument&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//    ^^^^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//    argument&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When we call this function we ask whether &lt;code&gt;&amp;quot;argument&amp;quot;&lt;/code&gt; is in the &lt;code&gt;string&lt;/code&gt; set (technically the singleton type is a subtype). The rules for which will be shown later, but in this example it is simple to see this call is valid as the string &lt;code&gt;&amp;quot;argument&amp;quot;&lt;/code&gt; has all the properties of being a string.&lt;/p&gt;
&lt;p&gt;From this we know that this call is valid. However if it were the case that we had &lt;code&gt;func(4)&lt;/code&gt; we find that type &lt;code&gt;4&lt;/code&gt;  does not have the properties of being a &lt;code&gt;string&lt;/code&gt; and so here we would raise a type error.&lt;/p&gt;
&lt;p&gt;There are many times questions this &amp;quot;subtype&amp;quot; question is asked, so here is a long list of all the places where a subtyping happens. In each case I have linked to where &lt;code&gt;is_subtype&lt;/code&gt; (or a wrapper function) is used in the ezno-checker.&lt;/p&gt;
&lt;p&gt;The first is in return types. When we return a value, we check that it is a subtype of the annotation specified in the function declarations.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// &amp;quot;hi&amp;quot; &amp;lt; number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// &amp;quot;hi&amp;quot; &amp;lt; number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/925cec9bd1cf03a7b845b84629c3b6f54b77fe5f/checker/src/features/variables.rs#L99&quot;&gt;Variable initial values&lt;/a&gt; (including &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/925cec9bd1cf03a7b845b84629c3b6f54b77fe5f/checker/src/features/functions.rs#L198&quot;&gt;default values&lt;/a&gt;) are another case&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// &amp;quot;hi&amp;quot; &amp;lt; number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// &amp;quot;hi&amp;quot; &amp;lt; number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/925cec9bd1cf03a7b845b84629c3b6f54b77fe5f/checker/src/context/environment.rs#L671&quot;&gt;Assignments after declaration&lt;/a&gt; (&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/925cec9bd1cf03a7b845b84629c3b6f54b77fe5f/checker/src/types/properties/assignment.rs#L122%3E&quot;&gt;including properties&lt;/a&gt;) is an extension of the case above&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// &amp;quot;hi&amp;quot; &amp;lt; number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; y&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { a: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;y.a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// &amp;quot;hi&amp;quot; &amp;lt; number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// &amp;quot;hi&amp;quot; &amp;lt; number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; y&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { a: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;y.a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// &amp;quot;hi&amp;quot; &amp;lt; number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Others include: &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/925cec9bd1cf03a7b845b84629c3b6f54b77fe5f/checker/src/features/mod.rs#L566&quot;&gt;&lt;code&gt;satisfies&lt;/code&gt;&lt;/a&gt;,  &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/925cec9bd1cf03a7b845b84629c3b6f54b77fe5f/checker/src/features/exceptions.rs#L164&quot;&gt;Try-catch&lt;/a&gt; (special to ezno-checker),  &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/925cec9bd1cf03a7b845b84629c3b6f54b77fe5f/checker/src/synthesis/functions.rs#L799&quot;&gt;Function overloads&lt;/a&gt;,&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/925cec9bd1cf03a7b845b84629c3b6f54b77fe5f/checker/src/synthesis/type_annotations.rs#L198&quot;&gt;Generic arguments to parameter extends in type annotations&lt;/a&gt;, &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/925cec9bd1cf03a7b845b84629c3b6f54b77fe5f/checker/src/types/calling.rs#L1425&quot;&gt;This constraint&lt;/a&gt; (special parameter case),
&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/925cec9bd1cf03a7b845b84629c3b6f54b77fe5f/checker/src/types/properties/mod.rs#L506&quot;&gt;Type based keys&lt;/a&gt; (which will get more of a mention in a future post), &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/925cec9bd1cf03a7b845b84629c3b6f54b77fe5f/checker/src/features/operations.rs#L253-L254&quot;&gt;Operator checking&lt;/a&gt; (this uses a wrapper method) and of course the above mentioned &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/925cec9bd1cf03a7b845b84629c3b6f54b77fe5f/checker/src/types/calling.rs#L1788&quot;&gt;Function arguments to parameters&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Subtyping allows us to reason whether about a substitution or assignment is valid. Like the fact we do not test each individual entry, subtyping of function parameters allows skipping all the individual checks already done in the function body.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x; &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// string &amp;lt;= string here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x; &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// string &amp;lt;= string and again&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x; &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// string &amp;lt;= string and here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;a&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Single check against parameter (aka does not result in 4 checks)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;a&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Single check again&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x; &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// string &amp;lt;= string here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x; &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// string &amp;lt;= string and again&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x; &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// string &amp;lt;= string and here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;a&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Single check against parameter (aka does not result in 4 checks)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;a&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Single check again&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;how-to-do-subtyping&quot; tabindex=&quot;-1&quot;&gt;How to do subtyping&lt;/h4&gt;
&lt;p&gt;Subtyping is the asking of a question whether one type is contained in another two. We can extend our Venn diagrams with an extra dimension and consider by considering one type being overlaid by another type. &lt;em&gt;If I have it all working correctly&lt;/em&gt;, you should be able to drag the sliders to move the sets each other. For the overlaid set to be a subtype we want to see no red colour here at the end of the end of the translation. We see that sets on the right end with items that don&#39;t fit into the base type and therefore is not a subtype. If we have no red, then we have that the top type is a subtype.&lt;/p&gt;
&lt;!--
{  %
 includewidget three-dimensional-set.html 
 %  
}
--&gt;
&lt;blockquote&gt;
&lt;p&gt;Note that this is a relation not an equality. At the end of the transition we can have left over yellow.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Sometimes the notation &lt;code&gt;&amp;lt;=:&lt;/code&gt; is used to denote this relation (the underline to denote that they can be equal and the &lt;code&gt;:&lt;/code&gt; which crops up all around type theory).&lt;/p&gt;
&lt;p&gt;X is a subtype of Y is equivalent to saying X is assignable to Y.&lt;/p&gt;
&lt;p&gt;From the above diagram we can conclude from the top-left case that &lt;code&gt;4&lt;/code&gt; is assignable to &lt;code&gt;number&lt;/code&gt; so &lt;code&gt;4 &amp;lt;=: number&lt;/code&gt; &lt;strong&gt;but not the top-right case&lt;/strong&gt; &lt;code&gt;&amp;quot;hello&amp;quot; &amp;lt;=: number&lt;/code&gt;. Similarly on the bottom row, from the left side we find that &lt;code&gt;number &amp;lt;=: number | string&lt;/code&gt; &lt;strong&gt;but not the other way round in the bottom right case&lt;/strong&gt; &lt;code&gt;number | string &amp;lt;=: number&lt;/code&gt;.&lt;/p&gt;
&lt;h5 id=&quot;subtyping-is-recursive&quot; tabindex=&quot;-1&quot;&gt;Subtyping is recursive&lt;/h5&gt;
&lt;p&gt;Because of the structural system, an individual test for relation can end up in many nested subtyping questions.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Sometimes cases can occur where subtyping can end up being cyclic. For this case a list of &amp;quot;currently checking pairs&amp;quot; is built so that subtyping can exit and not stack overflow.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 id=&quot;the-details&quot; tabindex=&quot;-1&quot;&gt;The details&lt;/h5&gt;
&lt;p&gt;Here is the table specification&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Left&lt;/th&gt;
&lt;th&gt;Right&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;th&gt;Also&lt;/th&gt;
&lt;th&gt;Why&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Type X&lt;/td&gt;
&lt;td&gt;Type X&lt;/td&gt;
&lt;td&gt;Subtype&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;They are equivalent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Primitive&lt;/td&gt;
&lt;td&gt;Constant of primitive&lt;/td&gt;
&lt;td&gt;Subtype&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Constant of primitive&lt;/td&gt;
&lt;td&gt;same constant&lt;/td&gt;
&lt;td&gt;Subtype&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Equal (same as first case)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Constant of primitive&lt;/td&gt;
&lt;td&gt;anything else&lt;/td&gt;
&lt;td&gt;Not subtype&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Only that value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A &amp;amp; B&lt;/td&gt;
&lt;td&gt;X&lt;/td&gt;
&lt;td&gt;A subtype X &amp;amp;&amp;amp; B subtype X =&amp;gt; subtype&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A | B&lt;/td&gt;
&lt;td&gt;X&lt;/td&gt;
&lt;td&gt;A subtype X || B subtype X =&amp;gt; subtype&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;td&gt;X &amp;amp; Y&lt;/td&gt;
&lt;td&gt;A subtype X || A subtype Y =&amp;gt; subtype&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;td&gt;X | Y&lt;/td&gt;
&lt;td&gt;A subtype X &amp;amp;&amp;amp; A subtype Y =&amp;gt; subtype&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Parameter with type constraint&lt;/td&gt;
&lt;td&gt;*&lt;/td&gt;
&lt;td&gt;Subtype&lt;/td&gt;
&lt;td&gt;Set parameter&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Parameter&lt;/td&gt;
&lt;td&gt;Parameter&lt;/td&gt;
&lt;td&gt;Subtype&lt;/td&gt;
&lt;td&gt;Set parameter&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;never&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;*&lt;/td&gt;
&lt;td&gt;Not subtype&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Nothing is in the empty set&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;any&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;*&lt;/td&gt;
&lt;td&gt;Subtype&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;*&lt;/td&gt;
&lt;td&gt;&lt;code&gt;never&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Subtype&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;*&lt;/td&gt;
&lt;td&gt;&lt;code&gt;any&lt;/code&gt; in TypeScript&lt;/td&gt;
&lt;td&gt;Not subtype&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;*&lt;/td&gt;
&lt;td&gt;&lt;code&gt;any&lt;/code&gt;*&lt;/td&gt;
&lt;td&gt;Not subtype&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;functions&lt;/td&gt;
&lt;td&gt;functions&lt;/td&gt;
&lt;td&gt;explained below&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;objects&lt;/td&gt;
&lt;td&gt;objects&lt;/td&gt;
&lt;td&gt;explained below&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;From the first row in this table we see that subtyping is a reflexive relation. This sort of thing is the &lt;em&gt;fast path&lt;/em&gt; of &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/8ce921e39c3d4e947063f206347b2932cee456ec/checker/src/types/subtyping.rs#L242-L244&quot;&gt;subtyping where we can skip any inspection of types&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Note when we have a conjugation of the &lt;strong&gt;left hand side of this relation&lt;/strong&gt; its logic follows its name. However when they are on the &lt;strong&gt;right hand side&lt;/strong&gt; it gets swapped.&lt;/p&gt;
&lt;h5 id=&quot;function-subtyping&quot; tabindex=&quot;-1&quot;&gt;Function subtyping&lt;/h5&gt;
&lt;p&gt;Sometimes functions end up on either side of this comparison. For example call-backs in parameters&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;cb&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(() &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//  ^^^^^^^^ subtyping here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;cb&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(() &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//  ^^^^^^^^ subtyping here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Similar to standard values, we also need to check that the function is also valid to be passed here.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;number =&amp;gt; string &amp;lt;=: *our function*&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The first property to check is that the function on the right hand side has less than or equal to the same number of parameters. If our function has more (required) parameters than the left-hand-side it means that we could call out function with missing data. If we have less then it will be fine as despite calls with extra arguments, it doesn&#39;t produce a runtime error, the arguments are simply discarded.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In Rust which is much stricter the counts have to be equal.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;One of the most interesting things is that: Comparing parameters happens in reverse. If we have the following.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;satisfies&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (a: string) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;satisfies&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (a: string) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If we compare the types of the first parameters in the normal way for the rest of the types like &lt;code&gt;&amp;quot;hi&amp;quot; &amp;lt;=: string&lt;/code&gt; , then we see it is valid. &lt;strong&gt;However&lt;/strong&gt; this function on the left-hand-side is &lt;strong&gt;not&lt;/strong&gt; &lt;code&gt;(a: string) =&amp;gt; number&lt;/code&gt; as it does not accept the whole set of strings as inputs (or as its codomain).&lt;/p&gt;
&lt;p&gt;For example for the following, if we subtype the same direction we end up with an error when we call it with argument &lt;code&gt;5&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; string.&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; string.&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;em&gt;fix&lt;/em&gt; for this is to &lt;em&gt;swap&lt;/em&gt; around the conventional subtyping operands. So instead we subtype &lt;code&gt;string &amp;lt;=: string | number&lt;/code&gt; which holds in the revised below case.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; item &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; item.&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; item;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;Test&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; item &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; item.&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; item;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;Test&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;This form is known as covariance and contravariance (I think)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Note that for default parameters and rest parameters the similar process is held.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The return type subtyping happens the normal way around. In the cases above we have &lt;code&gt;number &amp;lt;=: number&lt;/code&gt; which is fine because of the reflexive property of subtyping.&lt;/p&gt;
&lt;h4 id=&quot;object-subtyping&quot; tabindex=&quot;-1&quot;&gt;Object subtyping&lt;/h4&gt;
&lt;p&gt;When subtyping an against an object, we iterate over all the keys in the left hand side and check that&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It exists in the right hand side object&lt;/li&gt;
&lt;li&gt;That it indexed result has the subtype&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The following are all valid&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: { a: string }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: { a: string &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; number }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: { a: string &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; number }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: { a: string }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: { a: string &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; number }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: { a: string &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; number }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;This can mean that our right hand side can contain properties not in the right hand side. (explained near the start). This does cause some problems but that is for future posts as I think there is some progress that can be made in some of these cases.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;However these are invalid&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: { a: boolean } &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// &amp;quot;hi&amp;quot; is not a subtype of boolean&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: { a: string, b: string } &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// missing a required property&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: { a: boolean } &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// &amp;quot;hi&amp;quot; is not a subtype of boolean&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{ &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: { a: string, b: string } &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// missing a required property&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h5 id=&quot;collecting-mismatches-during-subtyping&quot; tabindex=&quot;-1&quot;&gt;Collecting mismatches during subtyping&lt;/h5&gt;
&lt;p&gt;In the above cases for object you can see there is some reasoning why the the results are not subtypes. Two good features to aim for in subtyping are&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;No early returns: collect as many property mismatches as possible (this is further justified/explained at the end of this post)&lt;/li&gt;
&lt;li&gt;Non-binary output: it is useful to know what exact property is missing. If the subtyping just returned a &lt;code&gt;bool&lt;/code&gt; then it would miss out on information that could be helpful to the user in fixing this issue.&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;In the future there should be better printing of this result in &lt;code&gt;ezno-checker&lt;/code&gt;. &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/167&quot;&gt;Currently some of the details are there but it needs some finishing touches&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;There is one other thing collected during this process, which you can read about in the inference section.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;subtyping%3A-nominal-types-vs-structural-type-systems&quot; tabindex=&quot;-1&quot;&gt;Subtyping: Nominal types vs structural type systems&lt;/h4&gt;
&lt;p&gt;One of the key differences between Rust and TypeScript is the fact that in Rust types are nominal. With nominal types while every type has &lt;em&gt;properties&lt;/em&gt;, the difference is that the above subtyping cases is condensed to just &lt;code&gt;is_subtype = A == B&lt;/code&gt; and does not look at individual properties in the definition of &lt;code&gt;A&lt;/code&gt; and &lt;code&gt;B&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This is done because in Rust types have layouts and so when substituting an object: the properties and discriminant values and offsets all have to line up. This can happen occasionally for types equal by definition but most of the time is just simpler to define it by instance rather than unfolding the definition.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;And Rust can do this because they started the language and could add syntax for definitions of types and didn&#39;t add general object types.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In TypeScript being a superset of JavaScript we have to deal with users being able to create objects without a schema, thus structural systems are needed to handle for &lt;code&gt;{ a: &amp;quot;hi&amp;quot; }&lt;/code&gt; or &lt;code&gt;JSON.parse&lt;/code&gt; being used as a value.&lt;/p&gt;
&lt;p&gt;Apart from the primitives (&lt;code&gt;string&lt;/code&gt;, &lt;code&gt;number&lt;/code&gt;, &lt;code&gt;boolean&lt;/code&gt;) there are no nominal types in TypeScript. If not for the equality shortcut, subtyping has to compare properties of sides to decide whether a value is assignable.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;While nominal systems better define boundaries of values and result in less edge cases, structural systems can be simpler to work with especially in the design of something. Many times in Rust I end up having to define sum types for small amount of types which be cumbersome and could be made simpler with a structural system which unfolds the unions during assignment.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;However, in Flow and &lt;a href=&quot;https://kaleidawave.github.io/ezno/comparison/#nominal-ness&quot;&gt;Ezno&lt;/a&gt; classes are nominal&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;disjoint-ness&quot; tabindex=&quot;-1&quot;&gt;Disjoint-ness&lt;/h3&gt;
&lt;p&gt;Alongside subtyping, another less-referenced but equally important type comparison function is disjoint-ness.&lt;/p&gt;
&lt;p&gt;While subtyping tests subsets. Disjoint-ness is a test that the intersection is empty. This is equivalent to saying there does not exist an element that satisfies both of the types or that the properties of the types are mutually exclusive.&lt;/p&gt;
&lt;p&gt;If you consider these two in the Venn diagrammatic way you can consider two sets disjoint when there is no overlap.&lt;/p&gt;
&lt;!--
{
% includewidget disjoint-test.html / 
% 
}
--&gt;
&lt;h4 id=&quot;implementation&quot; tabindex=&quot;-1&quot;&gt;Implementation&lt;/h4&gt;
&lt;p&gt;Similarly as subtyping we can resolve the results based on their definition&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;left&lt;/th&gt;
&lt;th&gt;right&lt;/th&gt;
&lt;th&gt;result&lt;/th&gt;
&lt;th&gt;example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;nominal type A&lt;/td&gt;
&lt;td&gt;nominal type B&lt;/td&gt;
&lt;td&gt;A != B&lt;/td&gt;
&lt;td&gt;&lt;code&gt;&amp;quot;hi&amp;quot; === 4&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A | B&lt;/td&gt;
&lt;td&gt;X&lt;/td&gt;
&lt;td&gt;A is disjoint with X &amp;amp;&amp;amp; B is disjoint with X&lt;/td&gt;
&lt;td&gt;&lt;code&gt;2 | 4&lt;/code&gt; is disjoint with &lt;code&gt;3&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A &amp;amp; B&lt;/td&gt;
&lt;td&gt;X&lt;/td&gt;
&lt;td&gt;A is disjoint with X || B is disjoint with X&lt;/td&gt;
&lt;td&gt;&lt;code&gt;number &amp;amp; 3&lt;/code&gt; is disjoint with &lt;code&gt;2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;object&lt;/td&gt;
&lt;td&gt;*&lt;/td&gt;
&lt;td&gt;properties that reside in both having disjoint values&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{ a: string }&lt;/code&gt;  is disjoint with &lt;code&gt;{ a: number}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;never&lt;/td&gt;
&lt;td&gt;*&lt;/td&gt;
&lt;td&gt;true&lt;/td&gt;
&lt;td&gt;...&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;any&lt;/td&gt;
&lt;td&gt;*&lt;/td&gt;
&lt;td&gt;false&lt;/td&gt;
&lt;td&gt;...&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Here nominal is the same as mentioned above can be a &lt;code&gt;number&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt; or a constant &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;&amp;quot;hi&amp;quot;&lt;/code&gt;, &lt;code&gt;false&lt;/code&gt; etc. again for the type intersection and union the result ends up involving recursion.&lt;/p&gt;
&lt;p&gt;Similar to the right hand side of subtyping, the &lt;code&gt;or&lt;/code&gt; and &lt;code&gt;and&lt;/code&gt; type use the opposite operator (this is probably because it is being framed from the point of view of disjoint-ness, if I reversed the name with &amp;quot;has some intersection&amp;quot; and changed the other cases then because of De Morgan identities it would use the result would be based on the same terminology as the inputs).&lt;/p&gt;
&lt;p&gt;Unlike subtyping, disjoint is symmetric (&lt;code&gt;disjoint A B = disjoint B A&lt;/code&gt;), which is why I only put in members for the first column because the results still stand swapping the left and right columns. This is why some of the &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/925cec9bd1cf03a7b845b84629c3b6f54b77fe5f/checker/src/types/disjoint.rs#L103-L114&quot;&gt;code looks repetitive&lt;/a&gt; but  it is the simplest way to account for both sides.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Functions and objects do not have disjoint-ness implementations are not implemented in the ezno-checker, &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/212&quot;&gt;you can help add them&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;uses-for-the-disjoint-relation-test&quot; tabindex=&quot;-1&quot;&gt;Uses for the disjoint relation test&lt;/h4&gt;
&lt;p&gt;This relation has slightly more esoteric uses that subtyping. But it can help resolve issues&lt;/p&gt;
&lt;h5 id=&quot;equality-well-defined&quot; tabindex=&quot;-1&quot;&gt;Equality well defined&lt;/h5&gt;
&lt;p&gt;Most programming languages have an equality operator. In most systems you can only use equality is only defined for the &lt;em&gt;same type&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In JavaScript we have an open book of values that equality operates on as equality always yields boolean no matter what operands.&lt;/p&gt;
&lt;p&gt;We can however deduce some cases where say an object is compared to a number, &lt;code&gt;{ name: &amp;quot;Josh&amp;quot; } === 4&lt;/code&gt; or even &lt;code&gt;&amp;quot;s&amp;quot; === false&lt;/code&gt; (although this is handled slightly differently in ezno-checker for constants).&lt;/p&gt;
&lt;p&gt;These cases are decided by the disjoint test. If they are not disjoint (aka have some overlap) then there must be at least one element that is in both and so this equality can be true or false.&lt;/p&gt;
&lt;p&gt;On the other hand if we find that they are disjoint we know that there cannot exist a pair that satisfies the equality and so we know that this expression is always false.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This behaviour extends to not equal. If we consider the operation &lt;code&gt;x !== y&lt;/code&gt; as  &lt;code&gt;!(x === y)&lt;/code&gt; we perform the same test (just the diagnostic prints that it is always true rather than always false).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 id=&quot;intersection-types-well-defined&quot; tabindex=&quot;-1&quot;&gt;Intersection types well defined&lt;/h5&gt;
&lt;p&gt;If you can remember all the way back in the beginning when we discussed some of the rules we around intersection types, we said if the two were disjoint then it was equivalent.&lt;/p&gt;
&lt;p&gt;When writing a intersection type reference, it is probably the writers intention to write a valid combination. So in the following case &lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=9zlky&quot;&gt;it is a probably a good idea to warn them their construction is invalid&lt;/a&gt;. (if they did want the &lt;code&gt;never&lt;/code&gt; type the could just refence it directly)&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;MySpecialType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;MySpecialType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Sometimes you can construct a disjoint type in places such as return type substitution and that is totally fine and normally valid. This warning is only for definitions.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h5 id=&quot;finding-cycles-in-type-aliases&quot; tabindex=&quot;-1&quot;&gt;Finding cycles in type aliases&lt;/h5&gt;
&lt;p&gt;Type aliases are a little complicated because they have to be defined before they have a value (this will be covered in a minute).&lt;/p&gt;
&lt;p&gt;Because of this, it can become a problem that a type can be defined in-terms of itself.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// or mututally&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// or mututally&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is a problem, the type isn&#39;t &lt;code&gt;never&lt;/code&gt; or &lt;code&gt;any&lt;/code&gt; or any other type. It is an invalid construction and not well defined. If it was well defined then it could break.&lt;/p&gt;
&lt;p&gt;Thus &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/8ce921e39c3d4e947063f206347b2932cee456ec/checker/src/context/environment.rs#L1490-L1505&quot;&gt;check disjoint-ness&lt;/a&gt;between the type alias and its value &lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=tysci&quot;&gt;to catch the issue&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Note we do not have to worry about generics.  We can&#39;t form this loop &lt;code&gt;type X&amp;lt;T&amp;gt; = T;&lt;/code&gt; because the alias always requires an argument. The initial problem  equivalent to &lt;code&gt;X&amp;lt;X&amp;lt;X&amp;lt;X&amp;lt;X&amp;lt;...&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt; which we can&#39;t construct.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;There are still some edge cases that just &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/211&quot;&gt;checking disjoint-ness doesn&#39;t account for&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;reading-%22properties%22-of-types&quot; tabindex=&quot;-1&quot;&gt;Reading &amp;quot;properties&amp;quot; of types&lt;/h3&gt;
&lt;p&gt;The subtype and disjoint operations are great. But other times they don&#39;t quite fit into our general type checking. Sometimes we need more manual lower level specific approaches to deal with types.&lt;/p&gt;
&lt;p&gt;The first place where we need do some more manual process if with object properties. Because in JavaScript objects are collections of properties, we can get fields from them through access expressions&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;obj.property&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// or&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;obj[&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;property&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;obj.property&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// or&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;obj[&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;property&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Depending on the type, we either have quite a straight-forward time calculating this object property (e.g. &lt;code&gt;({ property: string }).property =&amp;gt; string&lt;/code&gt;) or quite a hard time.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;The following are cases where we need to do some more manual inspection (rather than just disjoint or subtype operators) when working with types&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Property access. Covered above.&lt;/li&gt;
&lt;li&gt;Getting the &lt;em&gt;callable&lt;/em&gt; aspect of type. The details covered later.&lt;/li&gt;
&lt;li&gt;Numeric, bitwise, binary and relation operations computation on dependent types&lt;/li&gt;
&lt;li&gt;&lt;code&gt;await&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;instanceof&lt;/code&gt;, &lt;code&gt;typeof&lt;/code&gt; etc. Easier just to look at the type, rather than do easier&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;Note that subtyping and disjoint uses the property reading methods to do the subtyping and disjoint conclusion. For property access: we could define property access as subtype with &lt;code&gt;{ [*property*]: T }&lt;/code&gt; and return whatever the paired value of &lt;code&gt;T&lt;/code&gt; is but you can see how this becomes 1. a recursive definition and 2. is a lot more overhead than just looking up the property directly.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;reading-properties-on-conjugations&quot; tabindex=&quot;-1&quot;&gt;Reading properties on conjugations&lt;/h4&gt;
&lt;p&gt;With intersection types we pick the first result from either the left or the right (none else). With union types we have to check that both types have the property.&lt;/p&gt;
&lt;h4 id=&quot;retrieving-and-calling-functions&quot; tabindex=&quot;-1&quot;&gt;Retrieving and calling functions&lt;/h4&gt;
&lt;p&gt;Similar to retrieving properties, getting the function has to look at conjugations in the same way.&lt;/p&gt;
&lt;p&gt;When calling the function we have to handle both value arguments and type arguments. The first step is to handle the type arguments if they exist. In the following call we match them up (like regular parameters), this results in type arguments as &lt;code&gt;[(T, number), (U, string)]&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// [T = number, U = string]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;U&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// [T = number, U = string]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After any type arguments, we match up value arguments against regular parameters and check that they valid via subtyping (shown above). If type arguments were missing in the call-site then there is an additional inference step combined into subtyping which will be covered in due course.&lt;/p&gt;
&lt;h4 id=&quot;type-argument-substitution&quot; tabindex=&quot;-1&quot;&gt;Type argument substitution&lt;/h4&gt;
&lt;p&gt;When calling a function with generics the output type can be based on the type arguments. After all the value and type parameters are dealt with, we need to come up with a type for the result and thus the entire call expression, so that we can find faults in the following.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; t }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// cannot assign string to number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// cannot assign &amp;quot;hello&amp;quot; to number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// covered later :)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; t }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// cannot assign string to number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// cannot assign &amp;quot;hello&amp;quot; to number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// covered later :)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To do this we take our domain type &lt;code&gt;T&lt;/code&gt; and we walk its structure (in this case quite simple as there is no conjugations) and if find a generic type like &lt;code&gt;T&lt;/code&gt; we look in our parameter-argument pair array (which is &lt;code&gt;[(T, string)]&lt;/code&gt; in this case) and if any of the first pair items is type-equal (has exactly the same identifier) then we &lt;em&gt;replace&lt;/em&gt; the type in the output with the second pair item (in this case the &lt;code&gt;string&lt;/code&gt;).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In cases of objects, functions/methods etc we can apply the partially applied generic optimisation so that we don&#39;t walk the properties and substitute everything eagerly.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Substitution also happens for property access, for example &lt;code&gt;array1[4]&lt;/code&gt; we substitute &lt;code&gt;T&lt;/code&gt; as the value for &lt;code&gt;T&lt;/code&gt; on the array&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-type-checking-process&quot; tabindex=&quot;-1&quot;&gt;The type checking process&lt;/h2&gt;
&lt;p&gt;Technically type checking is really just the process of doing all the operations above (subtyping, disjoint-ness, property inspection, etc). The process of type checking on a module/file involves lots of small type checks on all the parts such as deep down to single expressions and single declarations.&lt;/p&gt;
&lt;p&gt;To do this we walk the AST in a recursive descent sort of way starting at the smallest expressions first. The type checking process is quite involved as we will see so we don&#39;t use standard walkers. Instead there is some technical details to walking that will be covered in the next few steps.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It needs to do several passes in blocks&lt;/li&gt;
&lt;li&gt;An expression needs to pass down an expected type&lt;/li&gt;
&lt;li&gt;An expression needs to return a value type&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;contexts&quot; tabindex=&quot;-1&quot;&gt;Contexts&lt;/h3&gt;
&lt;p&gt;So far we have been talking about bringing together random types. Contexts are the structure to the system, it is what allows us to reference types and reason about expressions in the system.&lt;/p&gt;
&lt;p&gt;Contexts store things, the fundamental information is based around two namespaces&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Variable names to types for expressions&lt;/li&gt;
&lt;li&gt;Named types to types for type annotations&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;parameter&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//                   ^^^^^^ get &amp;quot;number&amp;quot; type from the type namespace&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; parameter&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//     ^^^^^^^^^ get type of parameter from the variable namespace&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;parameter&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//                   ^^^^^^ get &amp;quot;number&amp;quot; type from the type namespace&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; parameter&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//     ^^^^^^^^^ get type of parameter from the variable namespace&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Rust has a third for macros&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Contexts are contained within other contexts. We start off with a root context. Subsequent contexts have a reference to their parent context. Once a scope has been exited the contents of the namespaces are dropped as they are no longer needed (unless stored for LSP work).&lt;/p&gt;
&lt;p&gt;Sometimes a item can have a variable representation and a type representation (for example &lt;code&gt;class&lt;/code&gt; has a general prototype type and a variable constructor type)&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;MyClass&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;constructor&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) { &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.n &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; n }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;MyClass&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;MyClass&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//       ^^^^^^^                 used as a prototype type equivalent to { n: number }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//                     ^^^^^^^   used as a value to mark the constructor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;MyClass&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;constructor&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) { &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.n &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; n }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;MyClass&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;MyClass&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//       ^^^^^^^                 used as a prototype type equivalent to { n: number }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//                     ^^^^^^^   used as a value to mark the constructor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;This comes with the confusing thing that the variable &lt;code&gt;MyClass&lt;/code&gt; is not the type of &lt;code&gt;MyClass&lt;/code&gt;. My class the expression when used produces objects of type &lt;code&gt;MyClass&lt;/code&gt; when constructed using the &lt;code&gt;new C(values)&lt;/code&gt;  syntax.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;types-vs-type-annotations&quot; tabindex=&quot;-1&quot;&gt;Types vs type annotations&lt;/h3&gt;
&lt;p&gt;Every term has a type. We can add notations for types.&lt;/p&gt;
&lt;p&gt;By convention many language instantiate parameters using chevrons &lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt; rather than parenthesis like regular function calls. Golang added (square) brackets. Lean has consistent syntax for both.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Languages that have chevron groupings for &lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt; generic arguments and &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; for the shift operator can create havoc for parsers that are not completely context aware.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Every term has a type that can be resolved from the context. Type annotations allow places to add type information (in the form of constraints).&lt;/p&gt;
&lt;p&gt;Slightly different to type annotations, there are also type declarations in the form of aliases and interfaces.&lt;/p&gt;
&lt;p&gt;These annotations behave differently to normal syntax in that (for the most part) they just denote information to the compiler. They can be totally erased (&lt;a href=&quot;https://bloomberg.github.io/ts-blank-space&quot;&gt;or replaced with whitespace&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;It is the sort of thing the &lt;code&gt;+&lt;/code&gt; operator will end up in the output as something like &lt;a href=&quot;https://www.felixcloutier.com/x86/addsd&quot;&gt;addsd&lt;/a&gt;.. But you won&#39;t normally be able to find the origins of the types of data.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Reflection can change this. Things like &lt;code&gt;enum&lt;/code&gt; have runtime meaning so there are edge cases where types&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;gradual-typing-with-elided-annotations&quot; tabindex=&quot;-1&quot;&gt;Gradual typing with elided annotations&lt;/h3&gt;
&lt;p&gt;Type annotations assign types to variables, parameters and function return types.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In languages that are supersets of a language that doesn&#39;t have types. Also sometimes types can become verbose to write and not applicable for non-foundation work (demos, experiments etc) and so systems which don&#39;t require any annotations.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;code&gt;any&lt;/code&gt; is used as the type for missing annotations. Because of this it simultaneously acts as &lt;code&gt;never&lt;/code&gt; and &lt;code&gt;any&lt;/code&gt; in the subtyping in an attempt to make it easier to adopt in codebases that don&#39;t have type annotations already.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I think parameter constraint inference could be a lot better in languages. The &lt;a href=&quot;https://hegel.js.org/docs/type-inference#arguments&quot;&gt;Hegel checker had a cool approach to this&lt;/a&gt; and &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/197&quot;&gt;there is some WIP things coming to ezno-checker&lt;/a&gt;, where we can be a lot smarter about missing annotations&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;inference&quot; tabindex=&quot;-1&quot;&gt;Inference&lt;/h2&gt;
&lt;p&gt;The inference process normally means forming a type based in its context.&lt;/p&gt;
&lt;h3 id=&quot;inferred-variable-constraints&quot; tabindex=&quot;-1&quot;&gt;Inferred variable constraints&lt;/h3&gt;
&lt;p&gt;In the following there is no constraint on variable &lt;code&gt;a&lt;/code&gt;. We could say that it type is &lt;code&gt;&amp;quot;hello&amp;quot;&lt;/code&gt; but that would break the later reassignment, therefore we instead chose the basis of &lt;code&gt;&amp;quot;hello&amp;quot;&lt;/code&gt; which is the &lt;code&gt;string&lt;/code&gt; type.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;world&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;world&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Because there are no nominal types, inferring this restrictions can become a little bit complicated. For example while totally valid JavaScript &lt;code&gt;a = 2&lt;/code&gt; would not be allowed because of the inferred constraint.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In Ezno the variable constraint and values have a special implementation thanks to aware-ness of re-assignments in side-effects. So this sort of &amp;quot;inference&amp;quot; doesn&#39;t have to be implemented. From this the system can just say that variables can be reassigned to &lt;code&gt;any&lt;/code&gt; and can be more flexible in cases (that you should probably not create anyway). However in some cases simpler to and more realistic (for example &lt;code&gt;for (let x = 0; ...)&lt;/code&gt;)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;inferred-type-arguments&quot; tabindex=&quot;-1&quot;&gt;Inferred type arguments&lt;/h3&gt;
&lt;p&gt;While functions can have generics parameters, we don&#39;t require them to be specified at call-sites. Show above before but we can have.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;identity&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; t }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;identity&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;identity&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; t }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;identity&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;He we &lt;em&gt;infer&lt;/em&gt; that the &lt;code&gt;T&lt;/code&gt; type parameter is a &lt;code&gt;number&lt;/code&gt;. This is done during subtyping, when we check &lt;code&gt;T &amp;lt;=: 5&lt;/code&gt; we see that &lt;code&gt;T&lt;/code&gt; does not have a value yet and so pick on out based on our RHS type &lt;code&gt;5&lt;/code&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;TSC has a two pass system first the bind phase. In Ezno I combined the two, merging it into the subtyping.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;More on how this works for in other cases in a future blog post.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;inferred-function-parameter-types&quot; tabindex=&quot;-1&quot;&gt;Inferred function parameter types&lt;/h3&gt;
&lt;p&gt;When we do the checking stage scanning expressions and other AST, we can &amp;quot;pass&amp;quot; down a expected type. This allows for adding types to parameters without them.&lt;/p&gt;
&lt;h4 id=&quot;return-type-%22inference%22&quot; tabindex=&quot;-1&quot;&gt;Return type &amp;quot;inference&amp;quot;&lt;/h4&gt;
&lt;p&gt;Similar to variable reassignment, we might also not have a return type for a function. There is probably many ways to handle this but in ezno-checker, a return type is picked based on control flow analysis when checking the inner block&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()     {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//          ^^^ no return annotation here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;256&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//  ^^^^^^ ^^^ returns `256` so we will say that number is the return type&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// func: () =&amp;gt; number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()     {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//          ^^^ no return annotation here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;256&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//  ^^^^^^ ^^^ returns `256` so we will say that number is the return type&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// func: () =&amp;gt; number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Actually in Ezno a &amp;quot;second&amp;quot; return type is always built under a slightly different mechanism. So you always sort of infer the return type. &lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=am2o2&quot;&gt;You can try that out here&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;reflection-and-narrowing-%2F-refining-a-type&quot; tabindex=&quot;-1&quot;&gt;Reflection and narrowing / refining a type&lt;/h3&gt;
&lt;p&gt;I will do a whole blog post on my approach to narrowing and more but I will give a brief overview.&lt;/p&gt;
&lt;p&gt;In JavaScript there are various expression level operations that allow us to inspect a type such as &lt;code&gt;typeof&lt;/code&gt; and &lt;code&gt;instanceof&lt;/code&gt;. Because there is no pattern matching (👀) the way to do things conditionally based on types is using these expressions.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Inspection of values for type information is known as reflection. You can see the wording when you think of a program telling you about itself.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; param &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//  ^^^^^^^^^^^^^^^^^^^^^^^^^ based on this expression&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; param;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//                ^^^^^ we decide this is of type string &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//                       inside this conditional block&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;typeof&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; param &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;string&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//  ^^^^^^^^^^^^^^^^^^^^^^^^^ based on this expression&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; param;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//                ^^^^^ we decide this is of type string &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//                       inside this conditional block&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The full approach involves build union types when the expressions involve logical or s &lt;code&gt;||&lt;/code&gt;  and unions when looking at logical ands &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;. Things get slightly more complicated with negation and predicate functions, so I will leave that for a future blog post.&lt;/p&gt;
&lt;h3 id=&quot;representing-types&quot; tabindex=&quot;-1&quot;&gt;Representing types&lt;/h3&gt;
&lt;p&gt;So we know we have seen how we might operate on types. But one of the hardest things for me what figuring out how to represent these in a checker. Writing the checker in Rust was initially challenging because of the constraints. Here are a few things about types that should be considered.&lt;/p&gt;
&lt;h4 id=&quot;types-can-be-cyclic&quot; tabindex=&quot;-1&quot;&gt;Types can be cyclic&lt;/h4&gt;
&lt;p&gt;Types can be recursive they can have properties that represents themselves. This proves difficult in Rust because the non-mark sweep garbage collector approach puts limits on what can be represented.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;While I call it an Arena, its just a &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/8ce921e39c3d4e947063f206347b2932cee456ec/checker/src/types/store.rs#L23-L24&quot;&gt;Vec&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Initially I thought just a &lt;code&gt;Rc&lt;/code&gt; would work, but that can run into deadlocks where a type which references itself &lt;em&gt;somehow&lt;/em&gt; cannot ever be freed because there is cycle in the reference. While not an issue in the CLI, in the situation of a LSP (the checking done in an editor) which stays around for a while, this memory leaking could crash the LSP over time&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Arenas also are a good fit here because the types stay around for a while after passes. We know when they are no longer used and we can do the clean-up manually. Individual counting would amount to a lot of increments and decrements here and there and would be too fine grained of an operation. If I do ever get around to a more efficient store for types, it will also be linked to the module and based on the lifetime of that.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;short-circuiting-and-continuing-on-errors&quot; tabindex=&quot;-1&quot;&gt;Short-circuiting and continuing on errors&lt;/h3&gt;
&lt;p&gt;One consideration with type checking is around short-circuiting.&lt;/p&gt;
&lt;p&gt;For example &amp;quot;type checking&amp;quot; the current file we find a issue with the first variable declaration&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;variable&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;something&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;Hello World&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; variable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;variable&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;something&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;Hello World&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; variable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now one way is to walk the tree and on the first issue we find we &lt;code&gt;return TypeError&lt;/code&gt;. But that would be pretty annoying to use this checker. We fix the issue (in this case either the RHS expression is incorrect or maybe our annotation isn&#39;t correct for this situation) and then re-run the checker to see it is fixed. This now shows a second issue with the &lt;code&gt;const something&lt;/code&gt; declaration.&lt;/p&gt;
&lt;p&gt;It would have been nice if this issue could have be presented to us on the first run. So we can improve the checker by rather than returning an error, we &lt;strong&gt;append to a list of errors&lt;/strong&gt;. So now on the first run we get three errors.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;There is a decision to be made here about the type of &lt;code&gt;const variable&lt;/code&gt; here? Do we make it of type &lt;code&gt;string&lt;/code&gt; or of type &lt;code&gt;4&lt;/code&gt; (aka &lt;code&gt;number&lt;/code&gt;). We could not define it at all but that seems invalid as the variable is defined.&lt;/p&gt;
&lt;p&gt;Here I decided to treat the annotation &lt;code&gt;: string&lt;/code&gt; as the type &lt;code&gt;const variable&lt;/code&gt; has (with a marker on the type to say it is an error).&lt;/p&gt;
&lt;p&gt;But there are cases when we can&#39;t rely on the annotation.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;NonExistantType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;NonExistantType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we take up unknown annotation as &lt;code&gt;any&lt;/code&gt; (with a marker)&lt;/p&gt;
&lt;p&gt;but there are other times where there isn&#39;t an annotation at all&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { prop: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;variable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; obj.property;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//                   ^^^^^^^^ &amp;quot;property&amp;quot; does not exist on { &amp;quot;prop&amp;quot;: number }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { prop: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;variable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; obj.property;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//                   ^^^^^^^^ &amp;quot;property&amp;quot; does not exist on { &amp;quot;prop&amp;quot;: number }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here we take up the value is &lt;code&gt;never&lt;/code&gt; (with a marker)&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This is also a tricky problem for syntax parsing. If we encounter syntax that doesn&#39;t look right such as &lt;code&gt;function func() { = if }&lt;/code&gt;, do we parse the RHS as only an expression or as full statements? There is a trade-off in flooding the user with a block of errors some of which might be dependent on a original step VS the original problem of only surfacing. Some of this can be negated by one-syntax error per file etc.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;While it might be good in CI to fail fast, when you are working live in an editor it is often common that some syntax might be incorrect. This handling of partially valid sources is needed for autocomplete etc. We actually need an AST to check before we can do this &lt;code&gt;let x = ;&lt;/code&gt;. Will be covered in a post all about parsing. Syntax errors are much more of a problem than with types.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;These set of features is current under the term &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/specification/specification.md#stability&quot;&gt;&amp;quot;stability&amp;quot;&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;types-vs-values-and-unknown-ness&quot; tabindex=&quot;-1&quot;&gt;Types vs values and unknown-ness&lt;/h2&gt;
&lt;h3 id=&quot;dependent-types&quot; tabindex=&quot;-1&quot;&gt;Dependent types&lt;/h3&gt;
&lt;p&gt;Dependent types were added to TSC because JavaScript does not have a specific structure for tagged unions of data. Instead a so a lot of existing APIs used these &amp;quot;tagging&amp;quot; pattern to discern between objects.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;declare&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getUserActivity&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;kind&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;follow&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ..., &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;to&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ... }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;kind&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;comment&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;on&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ..., &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;comment&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ... }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;kind&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;post&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ..., &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;caption&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ... }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;activity&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (activity.kind &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;follow&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (activity.kind &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;comment&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (activity.kind &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;post&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;declare&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getUserActivity&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;kind&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;follow&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ..., &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;to&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ... }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;kind&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;comment&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;on&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ..., &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;comment&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ... }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;kind&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;post&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ..., &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;caption&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ... }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;activity&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (activity.kind &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;follow&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (activity.kind &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;comment&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (activity.kind &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;post&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;This pattern is a lot easier to understand than using &lt;code&gt;from in activity&lt;/code&gt; checks.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;You can also use unions of classes with &lt;code&gt;instanceof&lt;/code&gt;. But functions such as &lt;code&gt;JSON.parse&lt;/code&gt; and &lt;code&gt;Response.prototype.json&lt;/code&gt; return objects without a prototype.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;5-as-a-type&quot; tabindex=&quot;-1&quot;&gt;&lt;code&gt;5&lt;/code&gt; as a type&lt;/h3&gt;
&lt;p&gt;In a sense &lt;code&gt;5&lt;/code&gt; as a type is the number type &lt;strong&gt;with&lt;/strong&gt; a identity type from &lt;em&gt;itself&lt;/em&gt; to the term &lt;code&gt;5&lt;/code&gt;. For simplicity  sake and because ezno-checker is a not based on something that supports propositions-as-types is simpler just to define &lt;code&gt;Constant&lt;/code&gt; as a variant of &lt;code&gt;Type&lt;/code&gt; and say that similar to &lt;code&gt;number&lt;/code&gt; having &lt;em&gt;properties&lt;/em&gt;, the type &lt;code&gt;5&lt;/code&gt; is something with all the behaviour/properties you would expect for a &lt;code&gt;5&lt;/code&gt; term.&lt;/p&gt;
&lt;h4 id=&quot;const-systems&quot; tabindex=&quot;-1&quot;&gt;&lt;code&gt;const&lt;/code&gt; systems&lt;/h4&gt;
&lt;p&gt;In some systems they allow dependent types only in certain places. Because in Rust, generics must extend specifically trait &lt;em&gt;types&lt;/em&gt;, there is a special &lt;code&gt;const&lt;/code&gt; modifier for parameters that reference types as the extends constraints instead so that these generic parameters expect arguments to be values rather than types. In Rust &lt;code&gt;const&lt;/code&gt; parameters are used to set the number of &lt;em&gt;lanes&lt;/em&gt; in its upcoming SIMD API. While you could create a &lt;code&gt;struct Eight;&lt;/code&gt; etc. Using this &lt;code&gt;const&lt;/code&gt; version means that you can use operators.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In TypeScript there is also the &lt;code&gt;const&lt;/code&gt; modifier for generic parameters which tells TypeScript to handle the arguments a little bit more tightly in these cases.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;The Zig language also has some interesting ways of handling types at compile time that I unfortunately didn&#39;t have the time to look at for this post. If you have some interesting posts about Zigs type system features (especially around &lt;code&gt;comptime&lt;/code&gt;) leave them in the comments.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;wrapping-up&quot; tabindex=&quot;-1&quot;&gt;Wrapping up&lt;/h3&gt;
&lt;p&gt;And that is all for now, hopefully you enjoyed this mostly high level overview of types and found some of the subtyping rules interesting.&lt;/p&gt;
&lt;p&gt;If you liked the diagrams interactive or not, let me know whether I should do them in the future?&lt;/p&gt;
&lt;p&gt;I would like to talk about the Curry-Howard isomorphism and Rust lifetime types in the future which are the more advanced parts of type theory. I also have &lt;em&gt;left over&lt;/em&gt; material on reflection and the taking a more interpretation/computational based approach to type checking. If either of those sound interesting you can thumbs up the comments and I will add it in.&lt;/p&gt;
&lt;p&gt;This post was suggested by one of my sponsors. If you want to read drafts of upcoming blog posts you &lt;a href=&quot;https://github.com/sponsors/kaleidawave&quot;&gt;can sponsor for $5 a month&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I am also &lt;a href=&quot;https://bsky.app/profile/kaleidawave.bsky.social&quot;&gt;now on Bluesky, if that interests you can follow on there&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This is the first in the trilogy of posts deep into type checking. In the next posts I will build on some of this with more on the advanced parts of TypeScript as well as some things I have been working on in my own approach for a type system. So stay tuned!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>The quest continues</title>
    <link href="https://kaleidawave.github.io/posts/the-quest-continues/"/>
    <updated>2024-05-31T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/the-quest-continues/</id>
    <summary>An update on the checker</summary>
    <content xml:lang="en" type="html">&lt;p&gt;It has been nearly a year since the last post so thought it would be good to do a much-needed status of the project! &lt;strong&gt;While not production-ready yet&lt;/strong&gt; there has been some great recent progress in the last year. &lt;strong&gt;The project has passed 2000 stars, 10 external contributions and it now passes over 200 checker tests&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;If you haven&#39;t heard of it yet, Ezno is a new TypeScript type checker that experiments with deeper analysis to raise new errors and find new optimisation opportunities!&lt;/p&gt;
&lt;p&gt;This post will go over more of the state of the compiler and tooling. While there has been some huge technical progress on the checking and compilation side, I will leave it out of this post and split the technical details across future blog posts!&lt;/p&gt;
&lt;h3 id=&quot;there-is-a-new-web-based-playground&quot; tabindex=&quot;-1&quot;&gt;There is a new web-based playground&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=klo1s&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/playground.png&quot; alt=&quot;playground&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This can be used to try the checker. You can see some of my favourite features here&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=tys5c&quot;&gt;Triangle number constant calculation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=klo1s&quot;&gt;Tracking a value across a closure&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=am2gw&quot;&gt;&lt;code&gt;Object.entries&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;Note the playground is WIP. Identifiers for sharing currently use a sequential index, which may change in the future.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;You can also try the checker locally with the CLI from the &lt;a href=&quot;https://github.com/kaleidawave/ezno/releases&quot;&gt;latest GH release&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;the-test-suite&quot; tabindex=&quot;-1&quot;&gt;The test suite&lt;/h3&gt;
&lt;p&gt;Since last year, I have started on a new collection of type-checking tests for the checker. In its latest release, the &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/specification/specification.md&quot;&gt;checker passes 235 tests&lt;/a&gt;!&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/passing-tests-may-2024.png&quot; alt=&quot;235 passing tests&quot; /&gt;&lt;/p&gt;
&lt;p&gt;There have been a lot of improvements in TypeScript features: &lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=ul98g&quot;&gt;complex subtyping&lt;/a&gt;, &lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=9zle0&quot;&gt;mapped types&lt;/a&gt; and &lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=tys5k&quot;&gt;&lt;code&gt;extends&lt;/code&gt; annotations&lt;/a&gt;. There is now a good foundation for the checker but there is a still a lot to do. There are some general JavaScript and TypeScript features to finish:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/35&quot;&gt;Inference&lt;/a&gt; (&lt;em&gt;was working, now being redone to work around Rust&#39;s mutability&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/122&quot;&gt;Narrowing&lt;/a&gt; (&lt;em&gt;got some parts working, working on getting more edge cases narrowed&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;More collection logic (&lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt; etc) (&lt;em&gt;array methods have been added, but are yet to work perfectly&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;Generators (&lt;em&gt;require storing and partially evaluating events&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;For-of (&lt;em&gt;should work by de-sugaring iterator calls, but a bit complex&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;Recursion&lt;/li&gt;
&lt;li&gt;Functioning queuing/non-synchronous calls and promises (&lt;em&gt;requires more unknown-ness and coordination between events&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/120&quot;&gt;Improving how types are stored&lt;/a&gt; (&lt;em&gt;current implementation doesn&#39;t scale for larger projects&lt;/em&gt;), which should &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/121&quot;&gt;then allow for more of the standard library to be used&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;node_modules&lt;/code&gt; imports (&lt;em&gt;files work, zipping source up with definition files is left to do&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;and there is a general need to improve all the different edge cases in which break the checker.&lt;/p&gt;
&lt;p&gt;There is no time frame or deadline for these. But as long as I can continue with the current trajectory they will eventually be all good!&lt;/p&gt;
&lt;p&gt;At the moment there are &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/specification/specification.md&quot;&gt;235 passing tests&lt;/a&gt;. &lt;strong&gt;The hope is that the checker should be ready for simple projects at around 300 passing tests and larger projects at around 500 passing tests&lt;/strong&gt;. You can see a &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/specification/to_implement.md&quot;&gt;collection of things that do not work in &lt;code&gt;to_implement.md&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;I am looking for more contributors to the checker tests&lt;/strong&gt;. If you have a favourite TypeScript or JavaScript feature not included in the current specification (or &lt;code&gt;to_implement.md&lt;/code&gt;) it would &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/100&quot;&gt;be really helpful to contribute it&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;These tests are authored as markdown and automatically built into tests that Rust can run. You can find out &lt;a href=&quot;https://github.com/kaleidawave/ezno/tree/main/checker/specification&quot;&gt;how a markdown file works as a test suite here&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;new-additions-from-contributors&quot; tabindex=&quot;-1&quot;&gt;New additions from contributors&lt;/h3&gt;
&lt;p&gt;Thanks to &lt;a href=&quot;https://github.com/CharlesTaylor7&quot;&gt;Charles Taylor&lt;/a&gt; for adding &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/132&quot;&gt;default value checking&lt;/a&gt; and &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/131&quot;&gt;checking for the type of catch variables&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=32i0ao&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/default-value-and-catch-check.png&quot; alt=&quot;default-value-and-catch-check&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thanks to &lt;a href=&quot;https://github.com/lemueldls&quot;&gt;Lemuel DLS&lt;/a&gt; for &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/127&quot;&gt;checking the edge case for destructuring with &lt;code&gt;this&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=ul98o&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/this-unbound.png&quot; alt=&quot;this-unbound&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thanks to &lt;a href=&quot;https://github.com/PatrickLaflamme&quot;&gt;Patrick Laflamme&lt;/a&gt; for &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/139&quot;&gt;adding excess property checking&lt;/a&gt; (including across conditionals which TS does not check currently as was pointed out &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/42&quot;&gt;in a this issue&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=74&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/excess-property.png&quot; alt=&quot;excess-property&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;and again for &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/138&quot;&gt;setters&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=jz6yo&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/setters.png&quot; alt=&quot;setters&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thanks to &lt;a href=&quot;https://github.com/Brayan-724&quot;&gt;Apika Luca&lt;/a&gt; for adding &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/141&quot;&gt;&lt;code&gt;import.meta&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/ezno/playground/?id=mha8&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/import-meta.png&quot; alt=&quot;import-meta&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Additionally, there have been improvements internally to the project. &lt;a href=&quot;https://github.com/wzwywx&quot;&gt;Wan&lt;/a&gt; &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/69&quot;&gt;added positions to events&lt;/a&gt; which have enabled emitting some new errors (that will be featured in the future). &lt;a href=&quot;https://github.com/JulesGuesnon&quot;&gt;Jules Guesnon&lt;/a&gt; added &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/84&quot;&gt;&lt;code&gt;export type&lt;/code&gt; parsing&lt;/a&gt; and &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/91&quot;&gt;improved the clippy configuration&lt;/a&gt;, which has helped keep things in order as the project grows. There are now &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/3&quot;&gt;fuzzing tests for the parser&lt;/a&gt; thanks to &lt;a href=&quot;https://github.com/jasikpark&quot;&gt;Caleb Jasik&lt;/a&gt; and &lt;a href=&quot;https://github.com/addisoncrump&quot;&gt;Addison Crump&lt;/a&gt;, which has caught some problems in parser and to string-ing (turning the AST back to a string). &lt;a href=&quot;https://github.com/nathanbabcock&quot;&gt;Nathan&lt;/a&gt; added the parsing for &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/23&quot;&gt;try-catch-finally&lt;/a&gt;. &lt;a href=&quot;https://github.com/markthree&quot;&gt;markthree&lt;/a&gt; added CJS support for the &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/15&quot;&gt;JS library&lt;/a&gt; and &lt;a href=&quot;https://github.com/H-Plus-Time&quot;&gt;Nicholas Roberts&lt;/a&gt; &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/114&quot;&gt;added type definition generation for the JS library&lt;/a&gt; (the type definitions have been very useful when building the playground). &lt;a href=&quot;https://github.com/kaleidawave/ezno/pulls?q=is%3Apr+-author%3Akaleidawave+&quot;&gt;You can see these contributions and more here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Despite Rust being a &lt;em&gt;non-trivial&lt;/em&gt; language to author and the type checker being very complicated and entangled, I have been impressed at the contributions to the type checker and project!&lt;/p&gt;
&lt;h4 id=&quot;bad-news&quot; tabindex=&quot;-1&quot;&gt;Bad news&lt;/h4&gt;
&lt;p&gt;Unfortunately, the first half of the year has been a bad month for JavaScript type checkers. First, the &lt;a href=&quot;https://github.com/swc-project/swc/issues/571#issuecomment-1915966297&quot;&gt;STC (speedy type checker) was abandoned&lt;/a&gt; and now &lt;a href=&quot;https://jsmonk.github.io/2024-01-29-last-days-of-hegel/&quot;&gt;Hegel is over&lt;/a&gt;. As someone who knows the difficulties of building a type checker, I commend the incredible work put into the two. &lt;a href=&quot;https://hegel.js.org/&quot;&gt;Hegel&lt;/a&gt; is especially impressive with its parameter constraint inference, which is an incredible feature &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/35&quot;&gt;I am hoping to implement as well in the checker&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I am hopeful that Ezno&#39;s wider feature scope compared to STC is more of a safe option (Ezno is not exclusively focused on checking performance). While I thought Hegel made some great trade-offs to provide better checking it seemed &lt;a href=&quot;https://hegel.js.org/try#MYewdgzgLgBAJiArgIwDYFMIC4YEEBO+AhgJ4A8YiAtsuvgHwwC8MA2gLJFQAWAdAAoBJADQxOPXgFEAugG4AUPID0SmJMIh8OACokADuhgAiAsXKUadekZgBLCHbCgqerrbSGA7rZ4wo+wxNCUgpqWnwYAB8YaHxbMABza3lQSFgLcIhtEABlbhBPHFMQjLoomKg4xMYWBBQMCAVS-Czc-M9ePUQIbgAKXoAWACYASl4oXMr4hN7RkYVU6Bh8JDA4dDhmeCQPCF4qIj1+uo8R5kYTjHGQADFbAA8N3pH5+SA&quot;&gt;maybe too much for potential users&lt;/a&gt; compared to TSC. I will explain more of how I think you can add better checking behavior while not breaking existing valid cases allowed by TSC in future blog posts!&lt;/p&gt;
&lt;p&gt;Also, the &lt;a href=&quot;https://crates.io/crates/ezno-checker&quot;&gt;ezno-checker&lt;/a&gt; is no longer included under &lt;a href=&quot;https://github.com/oxc-project/oxc&quot;&gt;Oxc&lt;/a&gt; and the only current way to use Ezno is through its own &lt;em&gt;toolchain&lt;/em&gt;. &lt;a href=&quot;https://github.com/oxc-project/oxc&quot;&gt;Oxc&lt;/a&gt; is an &lt;a href=&quot;https://oxc-project.github.io/blog/2023-12-12-announcing-oxlint.html#_50-100-times-faster-than-eslint&quot;&gt;impressive project for performance&lt;/a&gt; but differences in timelines and targets meant that it didn&#39;t make sense to put the work in maintaining the AST bindings. That is just for the moment though, the checker crate still keeps the checking logic separate from the AST/syntax implementation. Hopefully in the future when more of the language is implemented other tooling can consider reusing or copying parts!&lt;/p&gt;
&lt;h4 id=&quot;supporting-the-project&quot; tabindex=&quot;-1&quot;&gt;Supporting the project&lt;/h4&gt;
&lt;p&gt;I have written some &lt;a href=&quot;https://github.com/kaleidawave/ezno/labels/good-first-issue&quot;&gt;good first issues in the issue tracker&lt;/a&gt;. If there is something you want to contribute then I can help explain certain nuances in the checker and give steps to start! You also don&#39;t need to be good at Rust to contribute, &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/100&quot;&gt;adding more checking tests&lt;/a&gt; is useful for knowing how to approach new features! Type checkers are hard and Rust is not an easy language to write in. However, at this stage, you can have a really big impact by adding fundamental features! I appreciate all pull requests no matter how &lt;em&gt;ready&lt;/em&gt; they are (I would rather have some code that doesn&#39;t quite work than none at all).&lt;/p&gt;
&lt;p&gt;I have &lt;a href=&quot;https://github.com/sponsors/kaleidawave&quot;&gt;GitHub sponsors&lt;/a&gt;, which very generous people have signed up for! I have uploaded the LSP (a plugin for doing type checking in editors like vscode) to a sponsors-only repository and plan to also commit other experiments and early blog posts there. That is available at &lt;a href=&quot;https://github.com/sponsors/kaleidawave&quot;&gt;any level of sponsorship&lt;/a&gt; and I also plan to add code contributors to the main repository there as well!&lt;/p&gt;
&lt;p&gt;Unfortunately, a lot has come up in the last year which is why it has been a while since the last update. Again, a lot of progress has been made internally so I hopefully can share some amazing progress on type-checking and compilation soon!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Cool things in &#39;23</title>
    <link href="https://kaleidawave.github.io/posts/cool-things-23/"/>
    <updated>2023-12-20T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/cool-things-23/</id>
    <summary>A bunch of projects I have seen this year that I think are cool</summary>
    <content xml:lang="en" type="html">&lt;p&gt;I thought a good way to see the year out would be to show some appreciation for some tools and projects that I think made the &lt;em&gt;good list&lt;/em&gt; this year as well as some things I am looking for and forward to next year.&lt;/p&gt;
&lt;h3 id=&quot;tools&quot; tabindex=&quot;-1&quot;&gt;Tools&lt;/h3&gt;
&lt;h4 id=&quot;figma&quot; tabindex=&quot;-1&quot;&gt;Figma&lt;/h4&gt;
&lt;p&gt;Been using &lt;a href=&quot;https://www.figma.com/&quot;&gt;Figma&lt;/a&gt; as my main &lt;em&gt;graphics editor&lt;/em&gt; for a little over a year now. Here are some things I think are well designed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Components for composition&lt;/li&gt;
&lt;li&gt;Simple controls (such as &lt;code&gt;k&lt;/code&gt; for scaling, &lt;code&gt;space&lt;/code&gt; for moving)&lt;/li&gt;
&lt;li&gt;The pencil drawing tool. &lt;strong&gt;Although&lt;/strong&gt; I wish you could define the number of points it creates, I often want less vertices and detail and often get lag when there are a lot on the page.&lt;/li&gt;
&lt;li&gt;Auto layout options&lt;/li&gt;
&lt;li&gt;The outline/layers/elements panel. I like you can modify individual objects in unions and intersections.&lt;/li&gt;
&lt;li&gt;Plugins such as &lt;a href=&quot;https://www.figma.com/community/plugin/736000994034548392/lorem-ipsum&quot;&gt;lorem-ipsum&lt;/a&gt;, &lt;a href=&quot;https://www.figma.com/community/plugin/739493471028643540&quot;&gt;swap&lt;/a&gt;, &lt;a href=&quot;https://www.figma.com/community/plugin/1161618766697969707&quot;&gt;quick-tracing&lt;/a&gt; and for more advanced things &lt;a href=&quot;https://www.figma.com/community/plugin/757836922707087381&quot;&gt;scripter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;The free tier is enough to have infinite pages&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I also have been learning more about at pen/Bézier tool. Did you know you can press &lt;code&gt;ctrl&lt;/code&gt; to break out of a spline and also click on the node to get out of &lt;em&gt;curvy&lt;/em&gt; mode/make one-sided influence.&lt;/p&gt;
&lt;p class=&quot;small&quot;&gt;&lt;video src=&quot;https://kaleidawave.github.io/media/demos/figma-bezier-tool.mp4&quot; controls=&quot;&quot; title=&quot;Figma&quot;&gt;&lt;/video&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Also a tip here: if you are exporting a design to After Effects. As After Effects can&#39;t import SVGs you can instead export a EPS using &lt;a href=&quot;https://www.figma.com/community/plugin/849159306117999028&quot;&gt;this plugin&lt;/a&gt; and then import that into After Effects and break into a shape layer to keep the vector-ness of the graphics.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;obsidian&quot; tabindex=&quot;-1&quot;&gt;Obsidian&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;https://obsidian.md/&quot;&gt;Obsidian is a markdown editor&lt;/a&gt;. It is what I am currently using to write what you are currently reading. I will skip to the key things I like&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;LaTeX support. As someone who writes lots of mathematics notes it is great that I can do &lt;code&gt;$&#92;Gamma (z)=&#92;int _{0}^{&#92;infty }t^{z-1}e^{-t}{&#92;text{ d}}t$&lt;/code&gt; and it renders inline in the editor as &lt;div class=&quot;math&quot;&gt;&lt;svg style=&quot;vertical-align: -2.063ex;&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;21.198ex&quot; height=&quot;5.232ex&quot; role=&quot;img&quot; focusable=&quot;false&quot; viewBox=&quot;0 -1400.6 9369.6 2312.5&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;&lt;defs&gt;&lt;path id=&quot;MJX-1-TEX-N-393&quot; d=&quot;M128 619Q121 626 117 628T101 631T58 634H25V680H554V676Q556 670 568 560T582 444V440H542V444Q542 445 538 478T523 545T492 598Q454 634 349 634H334Q264 634 249 633T233 621Q232 618 232 339L233 61Q240 54 245 52T270 48T333 46H360V0H348Q324 3 182 3Q51 3 36 0H25V46H58Q100 47 109 49T128 61V619Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-1-TEX-N-28&quot; d=&quot;M94 250Q94 319 104 381T127 488T164 576T202 643T244 695T277 729T302 750H315H319Q333 750 333 741Q333 738 316 720T275 667T226 581T184 443T167 250T184 58T225 -81T274 -167T316 -220T333 -241Q333 -250 318 -250H315H302L274 -226Q180 -141 137 -14T94 250Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-1-TEX-I-1D467&quot; d=&quot;M347 338Q337 338 294 349T231 360Q211 360 197 356T174 346T162 335T155 324L153 320Q150 317 138 317Q117 317 117 325Q117 330 120 339Q133 378 163 406T229 440Q241 442 246 442Q271 442 291 425T329 392T367 375Q389 375 411 408T434 441Q435 442 449 442H462Q468 436 468 434Q468 430 463 420T449 399T432 377T418 358L411 349Q368 298 275 214T160 106L148 94L163 93Q185 93 227 82T290 71Q328 71 360 90T402 140Q406 149 409 151T424 153Q443 153 443 143Q443 138 442 134Q425 72 376 31T278 -11Q252 -11 232 6T193 40T155 57Q111 57 76 -3Q70 -11 59 -11H54H41Q35 -5 35 -2Q35 13 93 84Q132 129 225 214T340 322Q352 338 347 338Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-1-TEX-N-29&quot; d=&quot;M60 749L64 750Q69 750 74 750H86L114 726Q208 641 251 514T294 250Q294 182 284 119T261 12T224 -76T186 -143T145 -194T113 -227T90 -246Q87 -249 86 -250H74Q66 -250 63 -250T58 -247T55 -238Q56 -237 66 -225Q221 -64 221 250T66 725Q56 737 55 738Q55 746 60 749Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-1-TEX-N-3D&quot; d=&quot;M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-1-TEX-LO-222B&quot; d=&quot;M114 -798Q132 -824 165 -824H167Q195 -824 223 -764T275 -600T320 -391T362 -164Q365 -143 367 -133Q439 292 523 655T645 1127Q651 1145 655 1157T672 1201T699 1257T733 1306T777 1346T828 1360Q884 1360 912 1325T944 1245Q944 1220 932 1205T909 1186T887 1183Q866 1183 849 1198T832 1239Q832 1287 885 1296L882 1300Q879 1303 874 1307T866 1313Q851 1323 833 1323Q819 1323 807 1311T775 1255T736 1139T689 936T633 628Q574 293 510 -5T410 -437T355 -629Q278 -862 165 -862Q125 -862 92 -831T55 -746Q55 -711 74 -698T112 -685Q133 -685 150 -700T167 -741Q167 -789 114 -798Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-1-TEX-N-221E&quot; d=&quot;M55 217Q55 305 111 373T254 442Q342 442 419 381Q457 350 493 303L507 284L514 294Q618 442 747 442Q833 442 888 374T944 214Q944 128 889 59T743 -11Q657 -11 580 50Q542 81 506 128L492 147L485 137Q381 -11 252 -11Q166 -11 111 57T55 217ZM907 217Q907 285 869 341T761 397Q740 397 720 392T682 378T648 359T619 335T594 310T574 285T559 263T548 246L543 238L574 198Q605 158 622 138T664 94T714 61T765 51Q827 51 867 100T907 217ZM92 214Q92 145 131 89T239 33Q357 33 456 193L425 233Q364 312 334 337Q285 380 233 380Q171 380 132 331T92 214Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-1-TEX-N-30&quot; d=&quot;M96 585Q152 666 249 666Q297 666 345 640T423 548Q460 465 460 320Q460 165 417 83Q397 41 362 16T301 -15T250 -22Q224 -22 198 -16T137 16T82 83Q39 165 39 320Q39 494 96 585ZM321 597Q291 629 250 629Q208 629 178 597Q153 571 145 525T137 333Q137 175 145 125T181 46Q209 16 250 16Q290 16 318 46Q347 76 354 130T362 333Q362 478 354 524T321 597Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-1-TEX-I-1D461&quot; d=&quot;M26 385Q19 392 19 395Q19 399 22 411T27 425Q29 430 36 430T87 431H140L159 511Q162 522 166 540T173 566T179 586T187 603T197 615T211 624T229 626Q247 625 254 615T261 596Q261 589 252 549T232 470L222 433Q222 431 272 431H323Q330 424 330 420Q330 398 317 385H210L174 240Q135 80 135 68Q135 26 162 26Q197 26 230 60T283 144Q285 150 288 151T303 153H307Q322 153 322 145Q322 142 319 133Q314 117 301 95T267 48T216 6T155 -11Q125 -11 98 4T59 56Q57 64 57 83V101L92 241Q127 382 128 383Q128 385 77 385H26Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-1-TEX-N-2212&quot; d=&quot;M84 237T84 250T98 270H679Q694 262 694 250T679 230H98Q84 237 84 250Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-1-TEX-N-31&quot; d=&quot;M213 578L200 573Q186 568 160 563T102 556H83V602H102Q149 604 189 617T245 641T273 663Q275 666 285 666Q294 666 302 660V361L303 61Q310 54 315 52T339 48T401 46H427V0H416Q395 3 257 3Q121 3 100 0H88V46H114Q136 46 152 46T177 47T193 50T201 52T207 57T213 61V578Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-1-TEX-I-1D452&quot; d=&quot;M39 168Q39 225 58 272T107 350T174 402T244 433T307 442H310Q355 442 388 420T421 355Q421 265 310 237Q261 224 176 223Q139 223 138 221Q138 219 132 186T125 128Q125 81 146 54T209 26T302 45T394 111Q403 121 406 121Q410 121 419 112T429 98T420 82T390 55T344 24T281 -1T205 -11Q126 -11 83 42T39 168ZM373 353Q367 405 305 405Q272 405 244 391T199 357T170 316T154 280T149 261Q149 260 169 260Q282 260 327 284T373 353Z&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-1-TEX-N-A0&quot; d=&quot;&quot;&gt;&lt;/path&gt;&lt;path id=&quot;MJX-1-TEX-N-64&quot; d=&quot;M376 495Q376 511 376 535T377 568Q377 613 367 624T316 637H298V660Q298 683 300 683L310 684Q320 685 339 686T376 688Q393 689 413 690T443 693T454 694H457V390Q457 84 458 81Q461 61 472 55T517 46H535V0Q533 0 459 -5T380 -11H373V44L365 37Q307 -11 235 -11Q158 -11 96 50T34 215Q34 315 97 378T244 442Q319 442 376 393V495ZM373 342Q328 405 260 405Q211 405 173 369Q146 341 139 305T131 211Q131 155 138 120T173 59Q203 26 251 26Q322 26 373 103V342Z&quot;&gt;&lt;/path&gt;&lt;/defs&gt;&lt;g stroke=&quot;currentColor&quot; fill=&quot;currentColor&quot; stroke-width=&quot;0&quot; transform=&quot;scale(1,-1)&quot;&gt;&lt;g data-mml-node=&quot;math&quot;&gt;&lt;g data-mml-node=&quot;mi&quot;&gt;&lt;use data-c=&quot;393&quot; xlink:href=&quot;#MJX-1-TEX-N-393&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mo&quot; transform=&quot;translate(625,0)&quot;&gt;&lt;use data-c=&quot;28&quot; xlink:href=&quot;#MJX-1-TEX-N-28&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mi&quot; transform=&quot;translate(1014,0)&quot;&gt;&lt;use data-c=&quot;1D467&quot; xlink:href=&quot;#MJX-1-TEX-I-1D467&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mo&quot; transform=&quot;translate(1479,0)&quot;&gt;&lt;use data-c=&quot;29&quot; xlink:href=&quot;#MJX-1-TEX-N-29&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mo&quot; transform=&quot;translate(2145.8,0)&quot;&gt;&lt;use data-c=&quot;3D&quot; xlink:href=&quot;#MJX-1-TEX-N-3D&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;msubsup&quot; transform=&quot;translate(3201.6,0)&quot;&gt;&lt;g data-mml-node=&quot;mo&quot; transform=&quot;translate(0 1)&quot;&gt;&lt;use data-c=&quot;222B&quot; xlink:href=&quot;#MJX-1-TEX-LO-222B&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;TeXAtom&quot; transform=&quot;translate(1046.4,1088.1) scale(0.707)&quot; data-mjx-texclass=&quot;ORD&quot;&gt;&lt;g data-mml-node=&quot;mi&quot;&gt;&lt;use data-c=&quot;221E&quot; xlink:href=&quot;#MJX-1-TEX-N-221E&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;TeXAtom&quot; transform=&quot;translate(589,-896.4) scale(0.707)&quot; data-mjx-texclass=&quot;ORD&quot;&gt;&lt;g data-mml-node=&quot;mn&quot;&gt;&lt;use data-c=&quot;30&quot; xlink:href=&quot;#MJX-1-TEX-N-30&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;msup&quot; transform=&quot;translate(5171.7,0)&quot;&gt;&lt;g data-mml-node=&quot;mi&quot;&gt;&lt;use data-c=&quot;1D461&quot; xlink:href=&quot;#MJX-1-TEX-I-1D461&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;TeXAtom&quot; transform=&quot;translate(394,413) scale(0.707)&quot; data-mjx-texclass=&quot;ORD&quot;&gt;&lt;g data-mml-node=&quot;mi&quot;&gt;&lt;use data-c=&quot;1D467&quot; xlink:href=&quot;#MJX-1-TEX-I-1D467&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mo&quot; transform=&quot;translate(465,0)&quot;&gt;&lt;use data-c=&quot;2212&quot; xlink:href=&quot;#MJX-1-TEX-N-2212&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mn&quot; transform=&quot;translate(1243,0)&quot;&gt;&lt;use data-c=&quot;31&quot; xlink:href=&quot;#MJX-1-TEX-N-31&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;msup&quot; transform=&quot;translate(6848.2,0)&quot;&gt;&lt;g data-mml-node=&quot;mi&quot;&gt;&lt;use data-c=&quot;1D452&quot; xlink:href=&quot;#MJX-1-TEX-I-1D452&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;TeXAtom&quot; transform=&quot;translate(499,413) scale(0.707)&quot; data-mjx-texclass=&quot;ORD&quot;&gt;&lt;g data-mml-node=&quot;mo&quot;&gt;&lt;use data-c=&quot;2212&quot; xlink:href=&quot;#MJX-1-TEX-N-2212&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mi&quot; transform=&quot;translate(778,0)&quot;&gt;&lt;use data-c=&quot;1D461&quot; xlink:href=&quot;#MJX-1-TEX-I-1D461&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;TeXAtom&quot; data-mjx-texclass=&quot;ORD&quot; transform=&quot;translate(8202.6,0)&quot;&gt;&lt;g data-mml-node=&quot;mtext&quot;&gt;&lt;use data-c=&quot;A0&quot; xlink:href=&quot;#MJX-1-TEX-N-A0&quot;&gt;&lt;/use&gt;&lt;use data-c=&quot;64&quot; xlink:href=&quot;#MJX-1-TEX-N-64&quot; transform=&quot;translate(250,0)&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;g data-mml-node=&quot;mi&quot; transform=&quot;translate(9008.6,0)&quot;&gt;&lt;use data-c=&quot;1D461&quot; xlink:href=&quot;#MJX-1-TEX-I-1D461&quot;&gt;&lt;/use&gt;&lt;/g&gt;&lt;/g&gt;&lt;/g&gt;&lt;/svg&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;Plugins and theming support
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/artisticat1/obsidian-latex-suite&quot;&gt;LaTeX shortcut plugin&lt;/a&gt; is a must-have for writing mathematical formulas. I don&#39;t think I can go back to writing latex character by character. &lt;a href=&quot;https://gist.github.com/kaleidawave/9b332bfd6274862907d9db259fd8681f#file-snippets-jsonc&quot;&gt;My snippets are here&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/Maxymillion/zen&quot;&gt;Zen mode&lt;/a&gt; is also great. Using Zen mode and full-screen seems to be the best non-distraction mode for writing&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/PKM-er/Obsidian-Surfing&quot;&gt;Surfing extension&lt;/a&gt; is also a great way to find things without tabbing between windows&lt;/li&gt;
&lt;li&gt;One of the benefits of it being built using Electron is the ability to easily add custom CSS for the UI. My &lt;a href=&quot;https://gist.github.com/kaleidawave/9b332bfd6274862907d9db259fd8681f#file-snippets-css&quot;&gt;custom darker-than-dark CSS is here&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Canvas is nice for structuring ideas (I need to use this feature more). Although I normally find nested lists to be the best way to get ideas out of my brain&lt;/li&gt;
&lt;li&gt;Exporting to PDF (unfortunately no dark mode export)&lt;/li&gt;
&lt;li&gt;Split editors/panels are great&lt;/li&gt;
&lt;li&gt;Mobile app (although debugging Obsidian plug-ins on mobile is impossible)&lt;/li&gt;
&lt;li&gt;I always leave a couple of &lt;code&gt;TODO&lt;/code&gt;s tags in each document. It is nice it highlights it and can search it easily across documents. Although it really annoys me that an open parenthesis followed by hashtag doesn&#39;t create a tag. Hopefully, &lt;a href=&quot;https://forum.obsidian.md/t/parenthesis-and-more-will-block-hashtag-parsing/18479&quot;&gt;despite being brought up years ago&lt;/a&gt;, it will be improved in the future&lt;/li&gt;
&lt;li&gt;Viewing PDFs in the editor is incredibly useful. Although I wish it could natively render in dark mode (figures in white, background in black). I have tried with custom CSS with &lt;code&gt;filter: invert(1);&lt;/code&gt; it works, but I get weird/annoying chromatic aberration (see image below) and has the comedic but slightly annoying effect of inverting any images. Also had issues with scrolling PDFs losing their position and going into a weird state when the native one first came out. Hopefully, that has been fixed&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/demos/obsidian-dark-mode-pdf-chromatic-aberration.png&quot; alt=&quot;Chromatic aberration in obsidian&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Problems I have in Obsidian are&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Opening files can close a file I was working on. I wish it worked the same way as vscode&lt;/li&gt;
&lt;li&gt;Saving every keystroke. It makes my laptop fan spin up to max if I write files while the 11ty live reloading is on. Wish there was an option to add a timeout from 10ms-60s.&lt;/li&gt;
&lt;li&gt;Some way to split up a file by headings. I like big files, I don&#39;t want them rendered all at once.&lt;/li&gt;
&lt;li&gt;Sometimes slow, especially when it is the 3rd chromium based editor open&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So when I don&#39;t use Obsidian to edit I use&lt;/p&gt;
&lt;h4 id=&quot;helix&quot; tabindex=&quot;-1&quot;&gt;Helix&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;https://helix-editor.com/&quot;&gt;Helix&lt;/a&gt; is a code and text editor. It works in the command line similar to &lt;code&gt;vim&lt;/code&gt; and &lt;code&gt;emacs&lt;/code&gt;. Things I like&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple to set up, seems like most things work out of the box or are connected automatically&lt;/li&gt;
&lt;li&gt;Controls are a little opinionated but in a good way (although I still have to look up most of the advanced ones)&lt;/li&gt;
&lt;li&gt;Line wrapping&lt;/li&gt;
&lt;li&gt;Lots of (good) themes&lt;/li&gt;
&lt;li&gt;Split editors are good&lt;/li&gt;
&lt;li&gt;Finding in a file is good (I wish the global one was a little better and I really want a better global search and replace as I use that in vscode a lot)&lt;/li&gt;
&lt;li&gt;Multiple cursors in a column (&lt;code&gt;C&lt;/code&gt; or &lt;code&gt;shift+c&lt;/code&gt; ) and extending selection (&lt;code&gt;*&lt;/code&gt; to &lt;code&gt;v&lt;/code&gt; to &lt;code&gt;n&lt;/code&gt;) is good (what in vscode is &lt;code&gt;ctrl+d&lt;/code&gt;). Although I have had a few times where I also had another cursor down the page which I didn&#39;t realise (and clear cursors with &lt;code&gt;,&lt;/code&gt;) and ended up messing up a bunch of things offscreen&lt;/li&gt;
&lt;li&gt;The editor can be a bit slow sometimes, keystrokes lag in larger files. I think it might have to do with syntax highlighting. &lt;a href=&quot;https://helix-editor.com/news/release-23-10-highlights/#fuzzy-matching-with-nucleo&quot;&gt;They recently improved fuzzing when searching&lt;/a&gt; which I found a lot snappier afterwards&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Some improvements I would like to see in Helix&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Don&#39;t show images in the file picker. It also doesn&#39;t show files in &lt;code&gt;.gitignore&lt;/code&gt;d paths which is annoying&lt;/li&gt;
&lt;li&gt;I don&#39;t use the LSP integrations, as I find the placement of the diagnostics a little strange and sometimes slow. For quick edits to files and just drafting things it is really useful though&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;rust&quot; tabindex=&quot;-1&quot;&gt;Rust&lt;/h4&gt;
&lt;p&gt;I have &lt;a href=&quot;https://github.com/kaleidawave/ezno/graphs/contributors&quot;&gt;written a lot of Rust&lt;/a&gt; this year across a &lt;a href=&quot;https://github.com/kaleidawave?tab=repositories&amp;amp;q=&amp;amp;type=&amp;amp;language=rust&quot;&gt;number of projects&lt;/a&gt;. What has been amazing to see is some of the minor crates I have built being used in other people&#39;s projects. Somehow the total downloads across my crates are &lt;a href=&quot;https://crates.io/users/kaleidawave?sort=downloads&quot;&gt;now over 200k&lt;/a&gt;. Will be interesting to see the stats next year.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/demos/crates-io-download-2023.png&quot; alt=&quot;crates-io-downloads in 2023&quot; /&gt;&lt;/p&gt;
&lt;p&gt;I also recently &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/91&quot;&gt;received a PR that enabled clippy lints&lt;/a&gt;. I hadn&#39;t tried &lt;a href=&quot;https://doc.rust-lang.org/stable/clippy/usage.html&quot;&gt;&lt;code&gt;clippy&lt;/code&gt;&lt;/a&gt; before, beyond its default mode. The PR tidied up a lot of Ezno&#39;s internal code and &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/91#discussion_r1409312732&quot;&gt;also found a bug&lt;/a&gt;. If you use Rust you should check out the &lt;a href=&quot;https://rust-lang.github.io/rust-clippy/stable/index.html&quot;&gt;page that lists all of the clippy lints&lt;/a&gt; and consider turning on more by default.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://play.rust-lang.org/?version=stable&amp;amp;mode=debug&amp;amp;edition=2021&quot;&gt;Rust&#39;s online playground&lt;/a&gt; is still golden. It is a great way to start as a beginner or to test whether something works without spinning up a whole project. The option to build on nightly and do formatting are nice touches.&lt;/p&gt;
&lt;h3 id=&quot;lean&quot; tabindex=&quot;-1&quot;&gt;Lean&lt;/h3&gt;
&lt;p&gt;A slightly niche one. Excited to see &lt;a href=&quot;https://github.com/leanprover/lean4&quot;&gt;Lean 4 &lt;em&gt;released&lt;/em&gt; this year&lt;/a&gt;. A really interesting language, and when I don&#39;t get too try-hard about code golfing every proof it can be really fun. The main &lt;a href=&quot;https://lean-lang.org/lean4/doc/&quot;&gt;manual&lt;/a&gt; is okay, but the &lt;a href=&quot;https://lean-lang.org/theorem_proving_in_lean4/title_page.html&quot;&gt;theorem-proving&lt;/a&gt; and &lt;a href=&quot;https://lean-lang.org/functional_programming_in_lean/&quot;&gt;functional programming&lt;/a&gt; books go into much better detail. Would love to see an official blog (similar to Rust the release blog) to stay up to date with its development.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://leanprover-community.github.io/mathlib4_docs/&quot;&gt;Mathlib&lt;/a&gt;, a huge project &lt;a href=&quot;https://www.quantamagazine.org/building-the-mathematical-library-of-the-future-20201001/&quot;&gt;aimed at formalising a huge amount of mathematics&lt;/a&gt; is now on Lean 4. While it is a great foundation for proving things. I wish there was more intermediate material and codebases. I played around with Lean 3 a while ago and &lt;a href=&quot;https://github.com/kaleidawave/mathematics&quot;&gt;I have just open-sourced some things I wrote&lt;/a&gt;. You are only allowed to make fun of my proofs if you also put in a PR to shorten them 😆😉.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I also think the &lt;a href=&quot;https://openai.com/research/formal-math&quot;&gt;OpenAI&#39;s usage of Lean&lt;/a&gt; is incredible interesting. Mixing the output of AI with the formalisation foundations of type theory for validating output might be a big thing in the future. Anyway hopefully ChatGPT&#39;s cut off date gets sooner so that I can use it more for the newer syntax and features that arrived in the fourth version of Lean rather than from the third version.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;duckdb&quot; tabindex=&quot;-1&quot;&gt;DuckDB&lt;/h4&gt;
&lt;p&gt;Earlier in the year I built a &lt;a href=&quot;https://github.com/kaleidawave/duckdb-dictionary&quot;&gt;Python application with predictive text&lt;/a&gt;. I used the &lt;a href=&quot;https://duckdb.org/&quot;&gt;DuckDB&lt;/a&gt; CLI to do some &lt;a href=&quot;https://gist.github.com/kaleidawave/d51829a1209c87fa3fffb436a59c0a83&quot;&gt;modifications to a CSV file&lt;/a&gt; that &lt;a href=&quot;https://www.kaggle.com/datasets/soumendrak/dictionary-english-odia-word-pairs&quot;&gt;I took from a Kaggle&lt;/a&gt; (&lt;a href=&quot;https://www.kaggle.com/datasets/kaleidawave/english-dictionary&quot;&gt;my updated fork is here&lt;/a&gt;). Although it was a medium size dataset, running the data commands felt instant. Seems like a really good way to play with SQL on the client, it has &lt;a href=&quot;https://duckdb.org/docs/&quot;&gt;better documentation&lt;/a&gt; than I could find compared to SQLite and has some useful &lt;a href=&quot;https://duckdb.org/docs/sql/functions/overview&quot;&gt;internal functions&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;github-actions&quot; tabindex=&quot;-1&quot;&gt;GitHub actions&lt;/h3&gt;
&lt;p&gt;The great thing about GitHub repositories is the single public source of truth. One of the troubles I had before using actions was deploying. Before, I had to get the latest repo, deploy from my own machine (checking I had all the keys/credentials) and then commit with the updated version and state.&lt;/p&gt;
&lt;p&gt;With GitHub actions, on all my Rust projects I have set up &lt;a href=&quot;https://github.com/kaleidawave/crates-release-gh-action&quot;&gt;a workflow for deploying crates&lt;/a&gt; (crates = Rust packages) that not only deploys specific crates with certain versions given as inputs but also automates the tagging and committing of updated manifests. Any pull requests to the projects run lint checks and tests so I can see whether they are valid without cloning the changes locally (&lt;a href=&quot;https://gist.github.com/kaleidawave/16b0fc93459dd4dddc05d91955a40816#file-rust-yml&quot;&gt;I think I have now perfected my Rust setup&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;The other good thing about Repositories being centralised is benchmarking. If you do publish benchmarks it should be required that the methodology is public. With GitHub actions not only can you make the testing script public but also the exact logs and run using actions. I now have &lt;a href=&quot;https://github.com/kaleidawave/benchmarks&quot;&gt;a benchmarking repository&lt;/a&gt; that is all automated so anyone can go and test out benchmarks for themselves and PR to make corrections and improvements.&lt;/p&gt;
&lt;p&gt;One feature I want is: it would be nice if there was a way to have actions in a central place. Every time I set up a Rust repository I use the same workflows. Rather than &lt;a href=&quot;https://github.com/search?q=user%3Akaleidawave+language%3AYAML+%22cargo+check%22&amp;amp;type=code&quot;&gt;having the same bunch of files across repositories&lt;/a&gt;. It would be nice if you could do something like this in a &lt;code&gt;.github/workflows.yml&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;include&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	- &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;gist file here&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	- &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;maybe a repository link&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	- &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;someway to include a bunch of workflows on the main branch here&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;include&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	- &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;gist file here&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	- &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;maybe a repository link&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	- &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;someway to include a bunch of workflows on the main branch here&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;A tip for all those having difficulties wrangling GH actions: Create a private repository for testing and just go wild on there. By trying certain workflows and wrangling yaml syntax on there I have mostly avoided creating clutter on main repositories.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;on-the-command-line&quot; tabindex=&quot;-1&quot;&gt;On the command line&lt;/h4&gt;
&lt;p&gt;Here are some other tools that I use (when I remember what their parameters are)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/boyter/scc&quot;&gt;SCC counts source code lines&lt;/a&gt;. Other than some silly statistics by default, it is great and I use it (with its JSON output) to &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/.github/workflows/lines-of-code.yml&quot;&gt;keep track of how many lines I write in projects&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/sharkdp/bat&quot;&gt;bat&lt;/a&gt; prints the code for files &lt;strong&gt;with highlighting&lt;/strong&gt;. I wish &lt;code&gt;-pp&lt;/code&gt; was the default for &amp;lt;40 LOC files, but it&#39;s quite easy to remember 😆&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/jqlang/jq&quot;&gt;JQ, a JSON processor&lt;/a&gt;, selector and transformer. &lt;a href=&quot;https://jqplay.org/&quot;&gt;The playground&lt;/a&gt; for it is great&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/antonmedv/fx&quot;&gt;FX, a JSON viewer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cli.github.com/&quot;&gt;GitHub CLI&lt;/a&gt;. I always get mixed up between the &lt;code&gt;run&lt;/code&gt; and &lt;code&gt;workflows&lt;/code&gt; commands, but apart from that very good&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;javascript-and-the-web&quot; tabindex=&quot;-1&quot;&gt;JavaScript and the web&lt;/h3&gt;
&lt;h4 id=&quot;natto&quot; tabindex=&quot;-1&quot;&gt;Natto&lt;/h4&gt;
&lt;p&gt;Sometimes I just want to do a quick calculation. Maybe split some text and get the fifth line etc. Then sometimes I realise I now want that to be uppercase. Later, I might come back and depending on where I saved it have the following problems&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A shell session: where if it was saved, I now have to trawl through a bunch of unorganised lines and I can&#39;t edit functions because that isn&#39;t how REPLs work&lt;/li&gt;
&lt;li&gt;A file: which is sometimes easy to lose and then often hits the weird limit of being a file too large for the screen that is a mess of logic. Then I have to start up a runtime in watch mode and remember to log everything&lt;/li&gt;
&lt;li&gt;An online service (Replit, Codepen, etc): which can often be slow and often tricky to do things locally for privacy reasons (wouldn&#39;t want to accidentally copy an access token out to the world)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now instead of any of the above, I always go for &lt;a href=&quot;https://natto.dev/&quot;&gt;Natto&lt;/a&gt;. Natto has a unique design in that all the code is contained in blocks that have outputs that can be connected to other blocks as inputs. I have found that this node-based design is an ideal way to express demos and small pieces of code that are beyond the one expression mark, but before the point when it starts requiring sub-directories, a git repo and a linter.&lt;/p&gt;
&lt;p&gt;Here is a fun demo (&lt;a href=&quot;https://natto.dev/@kaleidawave/49901c79ce564c2f9196423913aab52f&quot;&gt;which you can even try here&lt;/a&gt;) I made where I used Natto to structure something I was experimenting with&lt;/p&gt;
&lt;p&gt;&lt;video src=&quot;https://kaleidawave.github.io/media/demos/natto-slider.mp4&quot; controls=&quot;&quot; title=&quot;Natto slider&quot;&gt;&lt;/video&gt;&lt;/p&gt;
&lt;p&gt;It has a nice interface (despite no dark mode, which should be a minimum for developer tools after the advent of CSS variables) and it is always instant to start. You can develop both private local nattos (which are saved as JSON files) as well as the option to publish them online. For one-offs, the default evaluation block prints the expression (rather than having to remember to &lt;code&gt;console.log&lt;/code&gt; it). It also can render HTML directly which is great.&lt;/p&gt;
&lt;p&gt;However, I have problems with the following&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I can&#39;t figure out a way to do timed iterations/run code at intervals. I think Natto is all built off React, so when using non-pure things like &lt;code&gt;setTimeout&lt;/code&gt;, I need to add special clean-up logic&lt;/li&gt;
&lt;li&gt;I wish there was an easier way to switch evaluation block type (aka just type &lt;code&gt;/functionbody/html&lt;/code&gt; in the editor)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;console.log&lt;/code&gt; goes off to the left of the screen when evaluation blocks are fully windowed&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Unfortunately I don&#39;t think it is maintained anymore :/&lt;/p&gt;
&lt;h4 id=&quot;val-town&quot; tabindex=&quot;-1&quot;&gt;Val Town&lt;/h4&gt;
&lt;p&gt;&amp;quot;&lt;a href=&quot;https://www.val.town/&quot;&gt;Val Town&lt;/a&gt; is a social website to write, run, and deploy code&amp;quot;. Similar to Natto, ValTown is a great playground for JavaScript code. Unlike Natto, its playground code can be deployed to servers to run on a schedule or a HTTP endpoint. I think it is the easiest and quickest way to get server-side code up and running.&lt;/p&gt;
&lt;p&gt;A while back I wrote some simple automation scripts that would generate and store SVGs after being called by a HTTP endpoint. It took a while to find a free service that could also store data and then I had to create a project locally and deal with bundling for my &amp;lt;50 LOC scripts. I now have no idea where those are on my filesystem, when they are run etc. Looking at ValTown it seems like it would have been perfect for hosting a bunch of my small automation scripts. It has a generous free tier, KV storage, logs and best of all is in this centralised store of code &lt;strong&gt;which can be made public&lt;/strong&gt;. &lt;a href=&quot;https://blog.val.town/blog/val-town-newsletter-14/&quot;&gt;With lots of features dropping&lt;/a&gt; I am interested to see where it goes!&lt;/p&gt;
&lt;p&gt;There are some &lt;a href=&quot;https://www.val.town/examples/use-cases&quot;&gt;really interesting examples and use cases&lt;/a&gt; and &lt;a href=&quot;https://www.val.town/?folderId=14715747-8ed3-41db-806f-f66c997c7102&quot;&gt;you can also try Ezno&#39;s checking API&lt;/a&gt; (which uses WASM behind the scenes).&lt;/p&gt;
&lt;h4 id=&quot;wasm&quot; tabindex=&quot;-1&quot;&gt;WASM&lt;/h4&gt;
&lt;p&gt;Web ASseMbly is a low-level format that can be run in &lt;a href=&quot;https://github.com/appcypher/awesome-wasm-runtimes&quot;&gt;various runtimes&lt;/a&gt; including JavaScript on the server and browser. Despite &lt;a href=&quot;https://github.com/kaleidawave/ezno&quot;&gt;Ezno&lt;/a&gt; being written in Rust &lt;a href=&quot;https://github.com/kaleidawave/ezno/tree/main/src/js-cli-and-library&quot;&gt;it can run in the browser and server runtimes&lt;/a&gt; thanks to the Rust compiler supporting WASM as a target and &lt;a href=&quot;https://rustwasm.github.io/docs/wasm-bindgen/&quot;&gt;wasm-bindgen&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/eliben/wasm-wat-samples&quot;&gt;WAT&lt;/a&gt; (WAsm Text representation) is a great way to play with the WASM format but I have also tried out &lt;a href=&quot;https://github.com/zksecurity/wasmati&quot;&gt;wasmati&lt;/a&gt; a DSL-like library for writing web assembly and it&#39;s pretty good. &lt;a href=&quot;https://wasi.dev/&quot;&gt;WASI&lt;/a&gt; is also an interesting development. It adds native system calls to the runtime, which if enables the &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/baa3a79126d33d54c24b60a03ce8c40d16b09cf1/src/js-cli-and-library/src/cli.js#L16-L31&quot;&gt;reduction of language-specific glue code&lt;/a&gt; might be great.&lt;/p&gt;
&lt;p&gt;Next year I would like to see &lt;a href=&quot;https://component-model.bytecodealliance.org/design/why-component-model.html&quot;&gt;the component proposal&lt;/a&gt; make some progress. I would like to see more exploration of how to make a WASM module that can manipulate strings in the host language without the overhead of copying memory in and out of the sandbox. And maybe I am being naive here, but I wonder whether there could be a WASM to machine code compiler, as I think the runtimes are at most JIT rather than AOT. I might be wrong about this, so feel free to correct me in the comments at the bottom of the page.&lt;/p&gt;
&lt;h3 id=&quot;cloudflare-web-analytics&quot; tabindex=&quot;-1&quot;&gt;Cloudflare web analytics&lt;/h3&gt;
&lt;p&gt;I use &lt;a href=&quot;https://www.cloudflare.com/en-gb/web-analytics/&quot;&gt;Cloudflare web analytics&lt;/a&gt; on this site. Numbers shouldn&#39;t matter, but if it is possible I would like to know whether my blog got 5 views of 5000. Unfortunately, the web portal is a pain as it requires 2FA every time (I wish it was only every two weeks), so I normally just read the email notifications (which have the benefit of being stored forever rather than expiring after three months).&lt;/p&gt;
&lt;h4 id=&quot;other-cool-things-for-the-web&quot; tabindex=&quot;-1&quot;&gt;Other cool things for the web&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/dgp1130/HydroActive&quot;&gt;HydraActive&lt;/a&gt; looks incredibly cool. A &lt;a href=&quot;https://kaleidawave.github.io/posts/prism-one-point-five/#hydration&quot;&gt;slightly different attempt to what I attempted a few years ago&lt;/a&gt;. Seems like a much simpler way to do what I attempted with less compilation and static analysis using what seems to be signals!&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://million.dev/&quot;&gt;Million.js&lt;/a&gt;: Looks like a great and simple library to implement in existing React applications that run on the client. Maybe one day VDOM will be over, but for now this looks to be a great &lt;a href=&quot;https://krausest.github.io/js-framework-benchmark/current.html&quot;&gt;way to speed up some updates in React land&lt;/a&gt; and since it is only a plugin it should be easy to add without big changes to existing code&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/winglang/wing&quot;&gt;Wing&lt;/a&gt; a programming language orientated for cloud specific things looks cool. I wish there were more experimental languages experimenting with things other than syntax, logic and runtime&lt;/li&gt;
&lt;li&gt;additionally &lt;a href=&quot;https://www.unison-lang.org/docs/fundamentals/abilities/&quot;&gt;unison&lt;/a&gt; is another language that has interesting &lt;em&gt;effect&lt;/em&gt; detection&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/arktypeio/arktype&quot;&gt;Arktype&lt;/a&gt; looks cool. Maybe the best implementation of types at runtime&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/oxc-project/oxc&quot;&gt;Oxc&lt;/a&gt; toolchain. Some &lt;a href=&quot;https://rustmagazine.org/issue-3/javascript-compiler/&quot;&gt;incredible engineering has been put into the parser&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;The &lt;a href=&quot;https://giscus.app/&quot;&gt;giscus&lt;/a&gt; comments box (despite being a next app in an iframe, which I unfortunately have to grit my teeth through). I found it incredibly simple to add to this site&lt;/li&gt;
&lt;li&gt;A few standards for JavaScript I have seen that I hope could simplify development
&lt;ul&gt;
&lt;li&gt;pattern matching &lt;a href=&quot;https://github.com/tc39/proposal-pattern-matching/issues/309&quot;&gt;IF AND ONLY IF IT IS BASED ON THIS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/tc39/proposal-defer-import-eval&quot;&gt;defer import eval&lt;/a&gt; hopefully we can get rid of dynamic imports (at least the non-static ones that are ridiculous)&lt;/li&gt;
&lt;li&gt;and &lt;a href=&quot;https://github.com/tc39/proposal-type-annotations&quot;&gt;type annotations&lt;/a&gt; if they &lt;a href=&quot;https://github.com/tc39/proposal-type-annotations/issues/197&quot;&gt;don&#39;t include &lt;code&gt;satisfies&lt;/code&gt;&lt;/a&gt;. Although I think there are lots of alternative approaches to reducing the problems from type annotations, if it means publishing code with type annotations to NPM is possible, then that would be great.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.11ty.dev/docs/&quot;&gt;11ty&lt;/a&gt; still powers this blog, haven&#39;t had any problems with it&lt;/li&gt;
&lt;li&gt;and &lt;a href=&quot;https://github.com/divriots/jampack&quot;&gt;Jampack&lt;/a&gt; optimises the output. A great SSG &lt;strong&gt;agnostic&lt;/strong&gt; optimiser!&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/leptos-rs/leptos&quot;&gt;Leptos&lt;/a&gt; is a reactive rendering library written in Rust. Looks like a great way to build client applications using all of the language and tooling of Rust&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.shuttle.rs/&quot;&gt;Shuttle&lt;/a&gt; is still the best way to start deploying Rust applications&lt;/li&gt;
&lt;li&gt;With a new build tool for JS written every week now. &lt;a href=&quot;https://github.com/unjs/unplugin&quot;&gt;unplugin&lt;/a&gt; is a great abstraction for building transformers and other tools for JS that can be used (almost) everywhere.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;things-i-am-on-the-lookout-for&quot; tabindex=&quot;-1&quot;&gt;Things I am on the lookout for&lt;/h3&gt;
&lt;p&gt;If you can find these (or make them), leave them in the comments below 👍&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;A terminal that renders markdown. More than a notebook. &lt;a href=&quot;https://code.visualstudio.com/docs/terminal/advanced#_image-support&quot;&gt;VS Code added images&lt;/a&gt;, I need more such as italic and bold decorations, links, code blocks, tables and for the whole nine yards LaTeX rendering.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I would like an email function as a service. Similar to an edge function with a HTTP endpoint. I want one that can email and it replies to that email with some information.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Maybe shouting into the void but I still can&#39;t grasp how for iOS alarms there isn&#39;t a mode with doesn&#39;t make sounds and excessively vibrate. How come such a simple feature doesn&#39;t exist??? Keep having to check the clock every five minutes in libraries.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I am always using the browser mini-player. It unfortunately only includes controls to pause with no feature for going back and forward ten seconds :(&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I also want GitHub for databases. As mentioned above I uploaded a dictionary dataset to &lt;a href=&quot;https://www.kaggle.com/&quot;&gt;Kaggle&lt;/a&gt; but there doesn&#39;t seem to be a way to make pull requests on it to add, fix or remove data. Maybe &lt;a href=&quot;https://huggingface.co/datasets&quot;&gt;HuggingFace&lt;/a&gt; might be the place for that but I am not sure. GitHub doesn&#39;t seem like the best place and doesn&#39;t have the same interactive tables that Kaggle and HuggingFace do.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I also really want a GitHub action/bot to apply &lt;code&gt;clippy --fix&lt;/code&gt; and &lt;code&gt;rustfmt format&lt;/code&gt; on the current PR. I don&#39;t know how I feel asking the author to do the sort of &lt;em&gt;bookkeeping&lt;/em&gt; in a project if simple checks fail. It would be nice if I could comment &lt;code&gt;@my-bot try fix lints and formatting&lt;/code&gt; and it runs it and commits the fixes (rather than me having to checkout and do it manually). Is this even a good idea, does it change who authored it when it appears in &lt;code&gt;git&lt;/code&gt; blame`? If you know a simple solution &lt;a href=&quot;https://github.com/kaleidawave/ezno/compare&quot;&gt;feel free to PR it&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Artificial intelligence has been a big thing this year, although I haven&#39;t observed anything cool wasn&#39;t from the previous year. I still really like: Dalle (they should give more free credits out now though) for generating artwork and ChatGTP is occasionally useful for finding synonyms of phrases and shell scripts but still isn&#39;t perfect. I would like an AI that can find songs from snippets and one to generate the one minute instrumentals from snippets would be amazing 🙏. I wish that more of the LLM chatbots were more up-to-date. They continue to be useless for anything that has happened in the last 18 months.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And that&#39;s it, to 2024 🎆🎇. If you worked on anything cool or something leave it in the comments!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>A preview of Ezno&#39;s checker</title>
    <link href="https://kaleidawave.github.io/posts/a-preview-of-the-checker/"/>
    <updated>2023-06-23T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/a-preview-of-the-checker/</id>
    <summary>Try it out today, what it does and more!</summary>
    <content xml:lang="en" type="html">&lt;h2 id=&quot;the-big-news&quot; tabindex=&quot;-1&quot;&gt;The big news&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/discussions/21&quot;&gt;Ezno&#39;s checker has now been open-sourced&lt;/a&gt;!&lt;/p&gt;
&lt;!-- You can now try it out through the [Oxc CLI](https://gist.github.com/kaleidawave/5dcb9ec03deef1161ebf0c9d6e4b88d8) or [Oxc playground on the web](https://boshen.github.io/oxc/playground). --&gt;
&lt;p&gt;This post is an overview of the current status of the project and goes into more detail about its unique approach to type-checking!&lt;/p&gt;
&lt;h3 id=&quot;the-aims%2Fdirection-of-the-project&quot; tabindex=&quot;-1&quot;&gt;The aims/direction of the project&lt;/h3&gt;
&lt;p&gt;Two things:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It is not aimed at having one-to-one parity with TSC. I made the &lt;a href=&quot;https://kaleidawave.github.io/posts/introducing-ezno/#types-and-typescript&quot;&gt;point last year&lt;/a&gt; that TypeScript&#39;s implementation of &lt;code&gt;any&lt;/code&gt; (and its other &lt;em&gt;backdoor&lt;/em&gt; behaviours) make doing type-based optimisations and complete type safety impossible. &lt;strong&gt;In my opinion, 90% of TSC features&#39; are great, so the aim is to be able to use existing syntax and not to break things in a bad ways&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Following on from 1) this is an experimental project. I want to explore new techniques and make previously impossible things possible! Building it from scratch makes it a lot more fun and easier to build for me.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;There is still a lot to do, a lot of JS features are still unimplemented&lt;/strong&gt;. I am only human :smile:, while I can implement features quickly, some other things will require time (also not to overwhelm myself).&lt;/p&gt;
&lt;h3 id=&quot;checking-performance&quot; tabindex=&quot;-1&quot;&gt;Checking performance&lt;/h3&gt;
&lt;p&gt;Don&#39;t want to dwell too much, there are a lot of places where Ezno could be faster I just haven&#39;t had the time to improve and the project is not at a stable place to work on optimising current behaviour. However I have seen a few comments that &amp;quot;Ezno does more, so will be slower&amp;quot;, so I did some investigating and have some pretty interesting numbers:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Benchmark 1: oxidation-compiler check ./demo.ts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Time (mean ± σ):      48.5 ms ±   1.4 ms    [User: 33.6 ms, System: 15.0 ms]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Range (min … max):    46.6 ms …  55.4 ms    60 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Benchmark 2: tsc --pretty demo.ts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Time (mean ± σ):      1.658 s ±  0.165 s    [User: 2.364 s, System: 0.103 s]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  Range (min … max):    1.542 s …  2.110 s    10 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Summary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  oxidation-compiler check ./demo.ts ran&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;   34.21 ± 3.55 &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; faster than tsc --pretty demo.ts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Benchmark 1: oxidation-compiler check ./demo.ts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Time (mean ± σ):      48.5 ms ±   1.4 ms    [User: 33.6 ms, System: 15.0 ms]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Range (min … max):    46.6 ms …  55.4 ms    60 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Benchmark 2: tsc --pretty demo.ts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Time (mean ± σ):      1.658 s ±  0.165 s    [User: 2.364 s, System: 0.103 s]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  Range (min … max):    1.542 s …  2.110 s    10 runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Summary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  oxidation-compiler check ./demo.ts ran&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;   34.21 ± 3.55 &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; faster than tsc --pretty demo.ts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These are rough benchmarks, so take these numbers with a grain of salt, they could go up or down. You can see the full result in my &lt;a href=&quot;https://github.com/kaleidawave/benchmarks/actions/runs/5335620178/attempts/1#summary-14441836482&quot;&gt;fancy automated benchmarking repository&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;stc%3A-speedy-type-checker&quot; tabindex=&quot;-1&quot;&gt;STC: Speedy type checker&lt;/h4&gt;
&lt;p&gt;Ezno is not the only TS checker written in Rust. &lt;a href=&quot;https://github.com/dudykr/stc&quot;&gt;STC&lt;/a&gt; (which was made public last year) is aimed at following TSC one-to-one, with the aim of improving the type checking time compared to TSC. Similar to Ezno in still being work in progress. Its current results look very impressive, being slightly faster than Ezno with Oxc.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;./stc/target/release/stc &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; demo.ts ran&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    2.72 ± 0.11 &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; faster than oxidation-compiler check ./demo.ts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    89.80 ± 3.56 &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; faster than tsc --pretty demo.ts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;./stc/target/release/stc &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; demo.ts ran&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    2.72 ± 0.11 &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; faster than oxidation-compiler check ./demo.ts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    89.80 ± 3.56 &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;times&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; faster than tsc --pretty demo.ts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;architecture-of-a-type-checker&quot; tabindex=&quot;-1&quot;&gt;Architecture of a type checker&lt;/h2&gt;
&lt;p&gt;A compiler is typically a chain of the following processes&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;lexing -&amp;gt; parsing -&amp;gt; type synthesis &amp;amp; checking -&amp;gt; output&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #c9d1d9&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;lexing -&amp;gt; parsing -&amp;gt; type synthesis &amp;amp; checking -&amp;gt; output&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292f&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ezno&#39;s current approach type synthesis &amp;amp; checking is a bit different from others, so here is some more insight.&lt;/p&gt;
&lt;h3 id=&quot;synthesis%3A-a-bridge-between-the-system-and-the-language&quot; tabindex=&quot;-1&quot;&gt;Synthesis: a bridge between the system and the language&lt;/h3&gt;
&lt;p&gt;The main &lt;code&gt;ezno-checker&lt;/code&gt; system contains high-level memory of the program (it&#39;s sort of its heap), it stores all the information about values and structures (encoded as types) and what functions and blocks do (encoded as events). This is all currently done in the &lt;a href=&quot;https://github.com/kaleidawave/ezno/tree/main/checker&quot;&gt;ezno-checker crate&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Synthesis on the other hand is taking AST and forming types from it.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Due to some &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/1&quot;&gt;issues with Ezno&#39;s own parser&lt;/a&gt; and after an offer to help from &lt;a href=&quot;https://twitter.com/boshen_c/status/1666633387073761281&quot;&gt;Boshen&lt;/a&gt; I figured it would be a good idea to make the synthesis work under other AST crates. To do this required some changes to split the checker logic from AST synthesis and the creation of &lt;a href=&quot;https://github.com/web-infra-dev/oxc/tree/main/crates/oxc_type_synthesis&quot;&gt;a new bridge crate&lt;/a&gt; between Oxc AST and Ezno checker.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/ezno-oxc-crates-diagram.png&quot; alt=&quot;Ezno and Oxc crates diagram&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The bridge crate consists of things like &lt;a href=&quot;https://github.com/web-infra-dev/oxc/blob/main/crates/oxc_type_synthesis/src/expressions.rs&quot;&gt;code that turns &lt;code&gt;oxc_ast::ast::Expression&lt;/code&gt; into a type&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;crate&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;synthesize_expression&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;FSResolver&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    expr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ast&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Expression&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    environment&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Environment&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    checking_data&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;CheckingData&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; instance &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; expr {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ast&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Expression&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;BooleanLiteral&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(boolean) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; checking_data&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;types&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;new_constant_type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ezno_checker&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Constant&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Boolean&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(boolean&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;value));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ast&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Expression&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;NullLiteral&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(_) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;NULL_TYPE&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;crate&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;synthesize_expression&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;FSResolver&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    expr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ast&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Expression&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    environment&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Environment&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    checking_data&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;CheckingData&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; instance &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; expr {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ast&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Expression&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;BooleanLiteral&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(boolean) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; checking_data&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;types&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;new_constant_type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ezno_checker&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Constant&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Boolean&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(boolean&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;value));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ast&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Expression&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;NullLiteral&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(_) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;NULL_TYPE&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thanks to this, a &lt;code&gt;check&lt;/code&gt; command was added to Oxc CLI and type checking was added to &lt;a href=&quot;https://boshen.github.io/oxc/playground&quot;&gt;the playground&lt;/a&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The playground is currently work in progress as I only added support in an a hour, expect some crashes that will show up in the browser console&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;As &lt;a href=&quot;https://rustmagazine.org/issue-3/javascript-compiler/&quot;&gt;Oxc has an incredibly fast&lt;/a&gt; and &lt;a href=&quot;https://github.com/web-infra-dev/oxc#parser-conformance&quot;&gt;correct&lt;/a&gt; parser it will be a great way to use Ezno&#39;s checker!&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This isn&#39;t the end of Ezno&#39;s own parser and CLI. It was incredibly useful building it, and it&#39;s 95% of the way there. It is great that the bindings exist with Oxc to offer a fast and reliable option to use Ezno&#39;s checker.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;an-interpreter-based-checker&quot; tabindex=&quot;-1&quot;&gt;An interpreter-based checker&lt;/h3&gt;
&lt;p&gt;Ezno tackles type-checking as evaluator/interpreter. However, unlike a real JS interpreter &lt;strong&gt;rather than passing around values it passes around types&lt;/strong&gt;. These are instead spaces that values live in.&lt;/p&gt;
&lt;p&gt;Evaluation&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/evaluator-points.gif&quot; alt=&quot;Regular evaluation&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Type-based&lt;/strong&gt; evaluation&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/evaluator-types.gif&quot; alt=&quot;Type-based evaluation&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Some big differences between what a value-based interpreter would be and Ezno&#39;s evaluator-based type checker:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Control flow has to handle different cases. In standard evaluation branches are binary, they either run or they don&#39;t run. In Ezno&#39;s checker, it&#39;s non-deterministic. (unless it can find the branching condition to be &lt;code&gt;true&lt;/code&gt;) It has to evaluate both branches and join the results together. Similarly, loops (and recursion) have undecidability to them and have to unify the results to reflect the possible amount of times the block can run.&lt;/li&gt;
&lt;li&gt;IO functions don&#39;t run. It doesn&#39;t make &lt;code&gt;fetch&lt;/code&gt; requests or &lt;code&gt;Math.random()&lt;/code&gt; at compile time, and it certainly doesn&#39;t ask the compiler&#39;s user to answer to &lt;code&gt;prompt&lt;/code&gt;. But all other functions whether from the runtime or user code are evaluated in some kind. &lt;strong&gt;It does the evaluations (most of the time) based on the body of a function, rather than a return type annotation.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;The other big difference between an interpreter is that it type checks annotations. While there is no rule that interpreter cannot do this, it doesn&#39;t hugely make sense&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This approach has benefits for languages with dynamic features. However, this approach still has benefits for stricter languages.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I have a longer, more theoretical post on some additional points, which I will get around to finishing at some point 😀&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Less theory, let&#39;s see how it works. The next part &lt;a href=&quot;https://gist.github.com/kaleidawave/5dcb9ec03deef1161ebf0c9d6e4b88d8&quot;&gt;goes over some code that is used in the current demo&lt;/a&gt;. You can try the above first to see how it is implementation works.&lt;/p&gt;
&lt;h2 id=&quot;inside-the-checker-and-its-features&quot; tabindex=&quot;-1&quot;&gt;Inside the checker and its features&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Note that a lot of this is a work in progress and things might have changed after the publishing of this post.&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&quot;contexts&quot; tabindex=&quot;-1&quot;&gt;Contexts&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;Context&lt;/code&gt;s store &lt;strong&gt;local&lt;/strong&gt; information.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/context-values.png&quot; alt=&quot;Context information&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This includes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Names to types&lt;/li&gt;
&lt;li&gt;Names to variables&lt;/li&gt;
&lt;li&gt;The current value of a variable&lt;/li&gt;
&lt;li&gt;The current properties on objects&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;They also contain a reference to the parent. Which it can get properties from:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/context-hierarchy.png&quot; alt=&quot;Context hierarchy&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;h4 id=&quot;what-kinds-of-contexts-are-there%3F&quot; tabindex=&quot;-1&quot;&gt;What kinds of contexts are there?&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Root&lt;/li&gt;
&lt;li&gt;Module&lt;/li&gt;
&lt;li&gt;Functions&lt;/li&gt;
&lt;li&gt;If and else blocks&lt;/li&gt;
&lt;li&gt;For statements&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Every environment (other than root) has a field for the &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/a4361ab08b5235f7b7a2d7c06586d779ed08e3b1/checker/src/context/environment.rs#L61&quot;&gt;&lt;code&gt;Scope&lt;/code&gt;&lt;/a&gt;. Scopes differentiate environments that are for a function body between if-else blocks (which we will see different behaviour for later).&lt;/p&gt;
&lt;p&gt;It can get slightly more complex as it (will) include&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;MyObject&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; input &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; otherValue&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//              ^^^^^^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;MyObject&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; input &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; otherValue&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//              ^^^^^^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Synthesizing the right-hand side of this logical expression (&lt;code&gt;otherValue&lt;/code&gt;) is done in a new context. This is because it conditionally runs (because of short-circuiting with logical and), any effects here have to be separated and narrowing can because it is known that &lt;code&gt;input&lt;/code&gt; has type &lt;code&gt;null&lt;/code&gt; here.&lt;/p&gt;
&lt;h3 id=&quot;the-different-contexts%2C-generalcontext-and-get_on_ctx!&quot; tabindex=&quot;-1&quot;&gt;The different contexts, &lt;code&gt;GeneralContext&lt;/code&gt; and &lt;code&gt;get_on_ctx!&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;There are two different types of contexts &lt;code&gt;Root&lt;/code&gt; and &lt;code&gt;Environment&lt;/code&gt; (aliases for &lt;code&gt;Context&amp;lt;Root&amp;gt;&lt;/code&gt; and &lt;code&gt;Context&amp;lt;environment::Syntax&amp;lt;&#39;a&amp;gt;&amp;gt;&lt;/code&gt;). Root is the top-level environment, it doesn&#39;t have events or a parent. Environments on the other hand represent the standard contexts found for written code. They record events (and other information) and have a parent. You can see the code for all contexts &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/a4361ab08b5235f7b7a2d7c06586d779ed08e3b1/checker/src/context/mod.rs#L222&quot;&gt;here&lt;/a&gt;, and the code specific for environments (not root contexts) &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/a4361ab08b5235f7b7a2d7c06586d779ed08e3b1/checker/src/context/environment.rs#L88&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This is structured using Rust generics and so can be a bit complex. To make it easier &lt;code&gt;GeneralContext&lt;/code&gt; is a sum type of the two contexts. To get properties on it, you can use &lt;code&gt;get_on_ctx!&lt;/code&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/7fc78261e9aa1d9012ff7e8cc7d07488459bf045/checker/src/context/mod.rs#L61-L95&quot;&gt;Not a huge fan of &lt;code&gt;macro_rules&lt;/code&gt; macros, but this seems to be a useful pattern I haven&#39;t seen elsewhere!&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;looking-up-information-with-parents_iter&quot; tabindex=&quot;-1&quot;&gt;Looking up information with &lt;code&gt;parents_iter&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;In JS information can be accessed in am above context&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;three&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//     ^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// What is the value of `x` here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;three&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//     ^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// What is the value of `x` here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/src/context/mod.rs#L1387&quot;&gt;&lt;code&gt;Context::parents_iter&lt;/code&gt;&lt;/a&gt; offers a way to walk up the parent chain to look for information.&lt;/p&gt;
&lt;h3 id=&quot;where-are-the-properties-of-types%3F&quot; tabindex=&quot;-1&quot;&gt;Where are the properties of types?&lt;/h3&gt;
&lt;p&gt;One way to have an object type would be to do&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;InterfaceType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	name&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	properties&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;HashMap&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;	//          ^^^^^^^^^^^^^^^^^^^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;	// Map properties to types&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;InterfaceType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	name&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	properties&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;HashMap&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeId&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;	//          ^^^^^^^^^^^^^^^^^^^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;	// Map properties to types&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/microsoft/TypeScript/blob/33eac2825ac548cf804e3d3abbc6a53b320a1de2/src/compiler/types.ts#L6326&quot;&gt;This is the way &lt;code&gt;TSC&lt;/code&gt; does it&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;However, the problem is that the value of properties is not always a global fact. In the two scopes&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (value) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	x.a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// here x.a = 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	x.a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// here x.a = 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (value) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	x.a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// here x.a = 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	x.a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// here x.a = 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;x.a&lt;/code&gt; has different values as shown in the comments.&lt;/p&gt;
&lt;p&gt;This is not true for all &lt;em&gt;facts&lt;/em&gt;, in the two scopes calling the function &lt;code&gt;x&lt;/code&gt; has the same behaviour.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() { &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (condition) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() { &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (condition) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;} &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Calling &lt;code&gt;x&lt;/code&gt; (the value not the reference) always yields the same as &lt;code&gt;x&lt;/code&gt; (and that can differ).&lt;/p&gt;
&lt;p&gt;Similar logic is done for the value variables, which are stored in &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/a4361ab08b5235f7b7a2d7c06586d779ed08e3b1/checker/src/context/mod.rs#L164&quot;&gt;&lt;code&gt;variable_current_value&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/422a3591c9b577efd00843fba9036b3a90a678b7/checker/src/context/mod.rs#L177&quot;&gt;So Ezno these are held under the context&lt;/a&gt;. While not implemented, prototypes and type narrowing will also work this way, being scoped to contexts rather than global.&lt;/p&gt;
&lt;p&gt;This is done for all types for simplicity, including interfaces.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;The variable and property facts applies to many other dynamic and static languages, not just JavaScript.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;scopes-and-dynamic-scopes&quot; tabindex=&quot;-1&quot;&gt;Scopes and dynamic scopes&lt;/h3&gt;
&lt;p&gt;As said before, every environment has a scope type. When looking for things between scopes, it needs to know whether the facts are constant between the scopes. For example&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (condition) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//      ^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// x is always 2 here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (condition) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//      ^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// x is always 2 here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However for&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//      ^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// x may not be 2 here if it is assigned a different value before a `func` function call&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//      ^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// x may not be 2 here if it is assigned a different value before a `func` function call&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;of&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; myArray) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//      ^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// x can be different again, because of the following statement&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;++&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;of&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; myArray) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//      ^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// x can be different again, because of the following statement&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;++&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first example of &lt;code&gt;if&lt;/code&gt; is a &lt;em&gt;static&lt;/em&gt; scope. Whereas for the &lt;code&gt;function&lt;/code&gt; and &lt;code&gt;for&lt;/code&gt; scopes they are considered &lt;em&gt;dynamic&lt;/em&gt; scopes and so the context logic does different behaviour in many cases when crossing these contexts.&lt;/p&gt;
&lt;h3 id=&quot;the-main-global-structures%3A-checkingdata%2C-diagnosticscontainer%2C-typemappings-and-typestore&quot; tabindex=&quot;-1&quot;&gt;The main global structures: &lt;code&gt;CheckingData&lt;/code&gt;, &lt;code&gt;DiagnosticsContainer&lt;/code&gt;, &lt;code&gt;TypeMappings&lt;/code&gt; and &lt;code&gt;TypeStore&lt;/code&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;CheckingData&lt;/code&gt; holds most information for a project it holds &lt;code&gt;DiagnosticsContainer&lt;/code&gt; and &lt;code&gt;TypeStore&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;DiagnosticsContainer&lt;/code&gt; is a container of &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/src/errors.rs&quot;&gt;Diagnostics&lt;/a&gt; that includes errors, warnings and general information.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;TypeStore&lt;/code&gt; stores all the types
&lt;ul&gt;
&lt;li&gt;Currently, types are referenced using &lt;code&gt;pub struct TypeId(u16)&lt;/code&gt; where the integer references an index into a &lt;code&gt;Vec&amp;lt;Type&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;This is a sort of arena. It means that types can safely reference themselves. While it does hold a lot of memory, types are needed between passes, so there isn&#39;t a lot to be dropped. It also means that it is easy to be serialized to a format that can be stored between runs to make checking times improved.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;This is a work in progress, it will be improved to split types by their file/source and probably other ways.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;type-and-typeid&quot; tabindex=&quot;-1&quot;&gt;&lt;code&gt;Type&lt;/code&gt; and &lt;code&gt;TypeId&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;One thing is types are immutable, once they are registered the actual &lt;code&gt;Type&lt;/code&gt; doesn&#39;t change! &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/src/types/mod.rs&quot;&gt;There are lots of kinds of &lt;code&gt;Type&lt;/code&gt;s&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The basics are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Named types (interfaces)&lt;/li&gt;
&lt;li&gt;Aliases&lt;/li&gt;
&lt;li&gt;Or (union types), these mean that they (inclusively) either have the properties on the left or on the right&lt;/li&gt;
&lt;li&gt;And (intersection types), these mean it satisfies the properties on the left and the right&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/src/types/terms.rs&quot;&gt;Constants/terms&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Functions&lt;/li&gt;
&lt;li&gt;Objects&lt;/li&gt;
&lt;li&gt;Root poly (parameters)&lt;/li&gt;
&lt;li&gt;Constructors (usage of parameters)&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;categorising-types&quot; tabindex=&quot;-1&quot;&gt;Categorising types&lt;/h4&gt;
&lt;p&gt;There are many types that are considered restrictions/general spaces. &lt;em&gt;These cannot be variable or property current values!&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Interfaces&lt;/li&gt;
&lt;li&gt;Intersection and unions&lt;/li&gt;
&lt;li&gt;Functions from type annotation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are three types that are considered &lt;em&gt;constants&lt;/em&gt; and so have a consistent total known behaviour&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Type::Constant&lt;/code&gt; which represents &lt;code&gt;number&lt;/code&gt;s, &lt;code&gt;string&lt;/code&gt;s, and &lt;code&gt;boolean&lt;/code&gt;s&lt;/li&gt;
&lt;li&gt;Functions defined in the source&lt;/li&gt;
&lt;li&gt;Immutable objects and objects where access does not cross a dynamic scope.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The bridge between the two are poly-types&lt;/p&gt;
&lt;h3 id=&quot;parameter-types-(poly-types)&quot; tabindex=&quot;-1&quot;&gt;Parameter types (poly-types)&lt;/h3&gt;
&lt;p&gt;Constants are great however, places where something can&#39;t be represented as a constant are known as poly-types. Function parameters are one example, also explicit generics.&lt;/p&gt;
&lt;h4 id=&quot;parameters&quot; tabindex=&quot;-1&quot;&gt;Parameters&lt;/h4&gt;
&lt;p&gt;Alongside explicit function parameters (such as &lt;code&gt;x&lt;/code&gt; in &lt;code&gt;function func(x) { ... }&lt;/code&gt;) there are other places in JS where a function can be parameterized. For example, closed over variables and &lt;code&gt;this&lt;/code&gt;. These are the most common poly-types.&lt;/p&gt;
&lt;h4 id=&quot;constructors%2C-the-higher-poly-types&quot; tabindex=&quot;-1&quot;&gt;Constructors, the higher poly-types&lt;/h4&gt;
&lt;p&gt;Parameters are root poly-types. All that is known is the origin. However, we want to carry more information. This is where &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/a4361ab08b5235f7b7a2d7c06586d779ed08e3b1/checker/src/types/mod.rs#L275&quot;&gt;constructors come in&lt;/a&gt;, they wrap &lt;strong&gt;any&lt;/strong&gt; poly type with additional information about its usage.&lt;/p&gt;
&lt;h4 id=&quot;closed-and-open-poly-types&quot; tabindex=&quot;-1&quot;&gt;Closed and open poly-types&lt;/h4&gt;
&lt;p&gt;The standard poly-type is closed. These are types such that a set of specializations can be formed.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { t, a }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { t, a }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After checking the above script, &lt;code&gt;a&lt;/code&gt; in the function body is specialized as &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;2&lt;/code&gt; and &lt;code&gt;T&lt;/code&gt; is specialized as &lt;code&gt;&amp;quot;hi&amp;quot;&lt;/code&gt; and &lt;code&gt;&amp;quot;hello&amp;quot;&lt;/code&gt;. In other words, we know a set of values that poly type takes throughout the life of the script.&lt;/p&gt;
&lt;h5 id=&quot;the-tracing-problem&quot; tabindex=&quot;-1&quot;&gt;The tracing problem&lt;/h5&gt;
&lt;p&gt;When evaluating &lt;code&gt;let p = document.body&lt;/code&gt;, &lt;code&gt;document&lt;/code&gt; can take on a range of values and so can &lt;code&gt;document.body&lt;/code&gt;. So in this way they are similar to regular function parameters. In fact, if JS had a main function without global variables it might look like:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;document&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, ...) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;document&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, ...) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So variables such as &lt;code&gt;document&lt;/code&gt; are considered similar to parameters. These are known as open poly-types. The open refers to the fact that what they are specialized to is out of the range of the checker. After checking, closed poly-types have a finite set of types they are specialized as. On the other hand, open have an unknown set.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This is still experimental and will probably be changed in some way at some point. Some open poly traces are completely useless, such as &lt;code&gt;Math&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;is-subtype&quot; tabindex=&quot;-1&quot;&gt;Is subtype&lt;/h4&gt;
&lt;p&gt;The &lt;code&gt;type_is_subtype&lt;/code&gt; function compares types. It is used when checking an argument is valid against a parameter, or a value assigned to variable meets it&#39;s constraint. It returns the following result:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;#[derive(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;SubTypeResult&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;IsSubtype&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;IsNotSubType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;NonEqualityReason&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;#[derive(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;SubTypeResult&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;IsSubtype&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;IsNotSubType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;NonEqualityReason&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The function checks whether the RHS has all the &#39;properties&#39; of the LHS.&lt;/p&gt;
&lt;h4 id=&quot;specialisation&quot; tabindex=&quot;-1&quot;&gt;Specialisation&lt;/h4&gt;
&lt;p&gt;In TypeScript (and Rust), call site generics can be inferred. This means that when calling a function with generic type parameters, the type parameters can be derived from the types of arguments if they were not already explicitly given&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;identity&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;identity&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(console)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;identity&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;identity&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(console)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The other thing is that in Ezno, every function parameter (apart from functions behind a generic) is generic (cascade information). So these &lt;em&gt;auto generics&lt;/em&gt; cannot be explicit set for parameters not explicitly generic.&lt;/p&gt;
&lt;p&gt;Ezno could resolve these types by scanning the argument list first. Instead during equality, while checking it &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/7fc78261e9aa1d9012ff7e8cc7d07488459bf045/checker/src/types/subtyping.rs#L67&quot;&gt;adds these values to a &lt;code&gt;SeedingContext&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&quot;constraint-inference&quot; tabindex=&quot;-1&quot;&gt;Constraint inference&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/35&quot;&gt;This is something being worked out&lt;/a&gt;. Most parameters have a fixed and known space they operate in. However, to enable full checking on sources without annotation, this restriction could be generated from its usage. See more in the issue.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;sinPlusOne&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;sin&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(x) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//     ^^^^^^^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// This call requires `x` to be a number. The poly&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// constraint needs to be modified to reflect this&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;sinPlusOne&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;sin&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(x) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//     ^^^^^^^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// This call requires `x` to be a number. The poly&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// constraint needs to be modified to reflect this&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;constant-functions&quot; tabindex=&quot;-1&quot;&gt;Constant functions&lt;/h3&gt;
&lt;p&gt;Some functions have a constant identifier (as shown above in the return annotation). Functions with this try and evaluate a result using &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/src/behaviour/constant_functions.rs&quot;&gt;custom Rust code&lt;/a&gt;. The Rust code only works for constants and so if it can&#39;t compute a result it will fail and &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/a4361ab08b5235f7b7a2d7c06586d779ed08e3b1/checker/src/types/calling.rs#L82-L150&quot;&gt;resort back to specializing the return type of the function&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This is what enables the following error to be caught&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/computed-property.png&quot; alt=&quot;Constant computed property&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;h3 id=&quot;events-and-effects&quot; tabindex=&quot;-1&quot;&gt;Events and effects&lt;/h3&gt;
&lt;p&gt;Events track mutations and other actions the code does. There are &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/src/events/mod.rs#L43&quot;&gt;many kinds of events that can happen&lt;/a&gt;, the simple ones are assignments and function calls.&lt;/p&gt;
&lt;p&gt;Events are the general term for these. When added to a &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/7fc78261e9aa1d9012ff7e8cc7d07488459bf045/checker/src/types/functions.rs#L13-L14&quot;&gt;&lt;code&gt;FunctionType&lt;/code&gt; these are referred to as (side) effects of a function&lt;/a&gt;. You can see the events being pulled &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/a4361ab08b5235f7b7a2d7c06586d779ed08e3b1/checker/src/context/mod.rs#L1027&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&quot;throw-and-try-catch&quot; tabindex=&quot;-1&quot;&gt;Throw and try-catch&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;https://kaleidawave.github.io/posts/ezno-23/#handling-errors&quot;&gt;Following on from a previous post&lt;/a&gt;, I managed to get try-catch statements to work and be type-safe 🎉&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/thrown-error.png&quot; alt=&quot;Thrown error&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;p&gt;While most of the time &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error&quot;&gt;Error&lt;/a&gt; is thrown, this covers every type. &lt;strong&gt;With dependent string types you also get the message of what types are thrown&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The above is a bit more complicated because it is throwing a parameter type. The actual value is found through type specialisation (in the same way that &lt;code&gt;let x: 2 = (a =&amp;gt; a)(2)&lt;/code&gt; works). The types of errors thrown are found using &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/a4361ab08b5235f7b7a2d7c06586d779ed08e3b1/checker/src/context/mod.rs#L1523&quot;&gt;this function&lt;/a&gt; (which again is work-in-progress).&lt;/p&gt;
&lt;h4 id=&quot;more-benefits-of-the-events-system&quot; tabindex=&quot;-1&quot;&gt;More benefits of the events system&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;They reuse types so can be specialized like the above&lt;/li&gt;
&lt;li&gt;Catch a lot of side effect cases, which can give more information rather than resorting to unknown-ness&lt;/li&gt;
&lt;li&gt;Calling functions to track what functions are called, which allows tree shaking of associated functions (functions under objects)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;They could be used as IR for generating more optimized output&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;some-extras&quot; tabindex=&quot;-1&quot;&gt;Some extras&lt;/h3&gt;
&lt;h4 id=&quot;hoisting-passes&quot; tabindex=&quot;-1&quot;&gt;Hoisting passes&lt;/h4&gt;
&lt;p&gt;Currently work in progress, but you can see how interfaces are checker before functions which is checked before any other structure in &lt;a href=&quot;https://github.com/web-infra-dev/oxc/blob/b31819d7a1b6708121f25ae8f314abc40ad68cf3/crates/oxc_type_synthesis/src/statements_and_declarations.rs#L20&quot;&gt;hoist_statements&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;printing-types&quot; tabindex=&quot;-1&quot;&gt;Printing types&lt;/h4&gt;
&lt;p&gt;Turning types into strings is done &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/src/types/printing.rs&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This also has to handle some other things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Recording what types have been printed types to not stack overflow in the case of cyclic types&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;diagnostics%2C-registering-errors-and-warnings&quot; tabindex=&quot;-1&quot;&gt;&lt;code&gt;Diagnostic&lt;/code&gt;s, registering errors and warnings&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/checker/src/diagnostics.rs&quot;&gt;diagnostics.rs&lt;/a&gt; has a long list of errors and how to turn them into general &lt;code&gt;Diagnostic&lt;/code&gt;s which can be printed to the CLI or presented in a LSP.&lt;/p&gt;
&lt;h3 id=&quot;developing&quot; tabindex=&quot;-1&quot;&gt;Developing&lt;/h3&gt;
&lt;p&gt;If you are interested in contributing, read &lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/main/CONTRIBUTING.md&quot;&gt;&lt;code&gt;CONTRIBUTING.md&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;what-is-next&quot; tabindex=&quot;-1&quot;&gt;What is next&lt;/h2&gt;
&lt;p&gt;You can read more standing issues on &lt;a href=&quot;https://github.com/kaleidawave/ezno/issues&quot;&gt;GitHub issues&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;There is still more to do&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Ezno&#39;s own CLI, with the &lt;a href=&quot;https://kaleidawave.github.io/posts/ezno-23/&quot;&gt;CLI REPL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/issues/22&quot;&gt;Finishing off the LSP&lt;/a&gt; (language service provider) with an associated VS Code extension to get type-checking results and helpers inside an editor.&lt;/li&gt;
&lt;li&gt;Using the types in optimising compilers!&lt;/li&gt;
&lt;li&gt;Some more experimental features in terms of syntax and things 👀&lt;/li&gt;
&lt;li&gt;Finishing Ezno&#39;s own parser, it is 95% there, so it would be nice to round it off&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;however-i-am-now-taking-a-break&quot; tabindex=&quot;-1&quot;&gt;However I am now taking a break&lt;/h3&gt;
&lt;p&gt;Unfortunately, I have other priorities for the next two months, so I can&#39;t &lt;a href=&quot;https://github.com/kaleidawave/ezno/pull/31&quot;&gt;spearhead additions and fixes&lt;/a&gt;. I will be around though to respond to certain things but development will be slower.&lt;/p&gt;
&lt;p&gt;Incredibly grateful for current &lt;a href=&quot;https://github.com/sponsors/kaleidawave&quot;&gt;sponsors&lt;/a&gt;. Any contributions including &lt;a href=&quot;https://github.com/sponsors/kaleidawave?frequency=one-time&quot;&gt;one-time&lt;/a&gt; are important for this project to keep going. For now, GitHub sponsors is looking like the easiest way to do this.&lt;/p&gt;
&lt;p&gt;Hopefully, I can keep this going as a chill experimental project without strings attached that I can keep improving part-time!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>My Rust infrastructure</title>
    <link href="https://kaleidawave.github.io/posts/my-rust-infrastructure/"/>
    <updated>2023-04-20T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/my-rust-infrastructure/</id>
    <summary>Some libraries and tools I have built to help with writing Rust.</summary>
    <content xml:lang="en" type="html">&lt;p&gt;I have written a lot of Rust over the last couple of years. Along the way of building a &lt;a href=&quot;https://github.com/kaleidawave/ezno&quot;&gt;compiler&lt;/a&gt;, I have built up a few smaller, generic crates and tools (infrastructure) to assist with writing Rust. I realised I haven&#39;t shared much about some of these, so I thought it would be a good opportunity to give an overview now.&lt;/p&gt;
&lt;p&gt;If you are interested in getting started with Rust: Last summer I wrote a collection of posts for &lt;a href=&quot;https://www.shuttle.rs/&quot;&gt;Shuttle&lt;/a&gt; (a great place to deploy Rust server applications). I wrote a bit about &lt;a href=&quot;https://www.shuttle.rs/blog/2022/07/28/patterns-with-rust-types&quot;&gt;patterns with Rust types&lt;/a&gt;, &lt;a href=&quot;https://www.shuttle.rs/blog/2022/06/30/error-handling&quot;&gt;how Rust tackles error handling&lt;/a&gt; or &lt;a href=&quot;https://www.shuttle.rs/blog/2022/06/09/the-builder-pattern&quot;&gt;the builder pattern&lt;/a&gt; as &lt;a href=&quot;https://www.shuttle.rs/blog/tags/all&quot;&gt;well as many others&lt;/a&gt;. If you are looking to get started with Rust, check those posts out as well as their platform (IMO currently the easiest way to deploy a Rust server application).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This post was meant to part of an upcoming post about the parser I just published, but this stuff didn&#39;t fit into that post. So I decided to split the content up. Look forward to a future post which includes things I learned about parsing and talks about some parser utility libraries I have written (&lt;a href=&quot;https://github.com/kaleidawave/source-map&quot;&gt;source-map&lt;/a&gt;, &lt;a href=&quot;https://github.com/kaleidawave/tokenizer-lib&quot;&gt;tokenizer-lib&lt;/a&gt; and &lt;a href=&quot;https://github.com/kaleidawave/derive-finite-automaton&quot;&gt;derive-finite-automaton&lt;/a&gt;) etc.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I&#39;ll start off with a couple of libraries I&#39;ve built that make it easier and shorter to write Rust code.&lt;/p&gt;
&lt;h2 id=&quot;building-macros-with-syn-helpers&quot; tabindex=&quot;-1&quot;&gt;Building macros with &lt;a href=&quot;https://github.com/kaleidawave/syn-helpers&quot;&gt;syn-helpers&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Proc(edural) macros are a way of generating Rust code. Derive proc macros are Rust&#39;s approach to reflection. I wrote at length about reflection, the use cases and an example with a comparison between vanilla JavaScript and Rust in &lt;a href=&quot;https://www.shuttle.rs/blog/2022/12/23/procedural-macros&quot;&gt;this post on Shuttle.rs&lt;/a&gt;. In summary, proc derive macros allow for generating the Rust &lt;code&gt;impl&lt;/code&gt; blocks based on the content of &lt;code&gt;struct&lt;/code&gt; and &lt;code&gt;enum&lt;/code&gt; declarations. For example, &lt;code&gt;#[derive(Debug)]&lt;/code&gt; above a &lt;code&gt;struct&lt;/code&gt; declaration finds fields and generates an &lt;code&gt;impl Debug for ...&lt;/code&gt; with an implementation that prints the field name alongside its runtime value.&lt;/p&gt;
&lt;p&gt;One thing about proc macros is that you will likely be reaching for the dependencies &lt;code&gt;syn&lt;/code&gt; and &lt;code&gt;quote&lt;/code&gt; when writing them. The &lt;a href=&quot;https://doc.rust-lang.org/stable/proc_macro/&quot;&gt;API&lt;/a&gt; for writing them only gives us a low-level sequence of tokens. Fortunately &lt;a href=&quot;https://github.com/dtolnay/syn&quot;&gt;syn&lt;/a&gt; exists and can parse the sequence into an &lt;a href=&quot;https://docs.rs/syn/latest/syn/struct.DeriveInput.html&quot;&gt;AST&lt;/a&gt;, which makes it a lot easier to read fields. Generating output code is also made easier as &lt;a href=&quot;https://github.com/dtolnay/quote&quot;&gt;quote&lt;/a&gt; offers a declarative using a macro: &lt;a href=&quot;https://docs.rs/quote/latest/quote/macro.quote.html&quot;&gt;&lt;code&gt;quote!&lt;/code&gt;&lt;/a&gt; (&lt;a href=&quot;https://docs.rs/syn/latest/syn/macro.parse_quote.html&quot;&gt;&lt;code&gt;parse_quote!&lt;/code&gt;&lt;/a&gt; is also a similar thing and equally useful).&lt;/p&gt;
&lt;p&gt;But just these on their own, it can still be difficult and verbose to build actual proc macros (&lt;a href=&quot;https://www.shuttle.rs/blog/2022/12/23/procedural-macros#procedural-macro-time&quot;&gt;the code in the post only worked for structs with named fields&lt;/a&gt;). Syn and quote offer great building blocks but they don&#39;t give you much help handling the setup required for derive proc macros.&lt;/p&gt;
&lt;p&gt;Some of the problems I have run that make the code harder and longer to write and can also introduce bugs:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Writing logic that can handle both &lt;code&gt;struct&lt;/code&gt;s and &lt;code&gt;enum&lt;/code&gt;s and their variants. You can use &lt;code&gt;self&lt;/code&gt; to reference data in a &lt;code&gt;struct&lt;/code&gt;, &lt;strong&gt;but not in&lt;/strong&gt; an &lt;code&gt;enum&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Creating expressions that access both named fields and unnamed fields&lt;/li&gt;
&lt;li&gt;Handling generics that exist on either of the structure or the trait and how to handle if the names clash&lt;/li&gt;
&lt;li&gt;How to handle attributes, how to access them at different levels&lt;/li&gt;
&lt;li&gt;Forgetting to add &lt;code&gt;#[automatically_derived]&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To make this easier, last year I wrote a &lt;em&gt;&#39;procedural macro framework&#39;&lt;/em&gt; that abstracted &lt;code&gt;syn&lt;/code&gt; and this process to handle all these cases for you. It&#39;s a bit difficult to explain in words so here is an example that calls &lt;code&gt;do_thing&lt;/code&gt; for all fields except ones marked with &lt;code&gt;ignore&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;syn_helpers&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;syn&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{parse_quote, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;DeriveInput&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;GenericParam&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ident&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Stmt&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;proc_macro2&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, quote,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    derive_trait, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;FieldMut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;HasAttributes&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Trait&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TraitItem&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeOfSelf&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Constructable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; my_trait &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Trait&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    name&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;my_crate&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;MyTrait&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    generic_parameters&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    items&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;vec!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TraitItem&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;new_method&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ident&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;method_one&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;call_site&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeOfSelf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Reference&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Vec&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;map_constructable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; constructable&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(constructable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get_fields_mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;fields_iterator_mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;flat_map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; field&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Stmt&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; field&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get_attributes&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; attr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_ident&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;ignore&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                            &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;None&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; reference &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; field&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get_reference&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                            &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;do_thing&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(#reference);))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;collect&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    )],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; r#struct&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;DeriveInput&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        b&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;i32&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; stream &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;derive_trait&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(r#struct, my_trait);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assert_eq!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    stream&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;to_string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        #[automatically_derived]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;impl&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;my_crate&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;MyTrait&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;method_one&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;ref&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; _0, b&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;ref&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; _1 } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;do_thing&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(_0);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;do_thing&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(_1);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;to_string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;syn_helpers&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;syn&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{parse_quote, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;DeriveInput&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;GenericParam&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ident&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Stmt&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;proc_macro2&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, quote,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    derive_trait, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;FieldMut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;HasAttributes&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Trait&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TraitItem&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeOfSelf&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Constructable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; my_trait &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Trait&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    name&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;my_crate&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;MyTrait&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    generic_parameters&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    items&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;vec!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TraitItem&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;new_method&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ident&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;method_one&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;call_site&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeOfSelf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Reference&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Vec&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;map_constructable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; constructable&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(constructable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get_fields_mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;fields_iterator_mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;flat_map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; field&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Stmt&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; field&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get_attributes&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; attr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_ident&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;ignore&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                            &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;None&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; reference &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; field&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get_reference&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                            &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;do_thing&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(#reference);))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;collect&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    )],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; r#struct&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;DeriveInput&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        b&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;i32&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; stream &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;derive_trait&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(r#struct, my_trait);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assert_eq!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    stream&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;to_string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        #[automatically_derived]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;impl&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;my_crate&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;MyTrait&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;method_one&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;ref&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; _0, b&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;ref&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; _1 } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;do_thing&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(_0);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;do_thing&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(_1);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;to_string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Benefits of using the crate here&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;map_constructable&lt;/code&gt; handles both enums variants and &lt;code&gt;struct&lt;/code&gt;-ures.&lt;/li&gt;
&lt;li&gt;The code uses the &lt;a href=&quot;https://docs.rs/syn-helpers/0.4.3/syn_helpers/trait.Field.html&quot;&gt;&lt;code&gt;Field&lt;/code&gt;&lt;/a&gt; trait which abstracts over generating expressions to access fields. Handling named and unnamed variants is automated away&lt;/li&gt;
&lt;li&gt;For fields whose type contains generics, it can add necessary &lt;code&gt;where&lt;/code&gt; clauses if the trait is called on that field&lt;/li&gt;
&lt;li&gt;The macro also gets a structure. You get a more declarative code by laying out the &lt;a href=&quot;https://docs.rs/syn-helpers/0.4.3/syn_helpers/struct.Trait.html&quot;&gt;&lt;code&gt;Trait&lt;/code&gt;&lt;/a&gt; with the items you need to implement. Those methods contain functions that handle generating the output.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, in the parser, I currently have a way of &lt;em&gt;visiting nodes&lt;/em&gt; (running a set of functions over them) and automating this implementation becomes quite simple using the &lt;code&gt;syn-helpers&lt;/code&gt; library.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;proc_macro&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TokenStream&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;std&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;error&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Error&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;string_cases&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;StringCasesExt&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;syn_helpers&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    derive_trait,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;proc_macro2&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ident&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;quote&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, format_ident},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;syn&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{parse_macro_input, parse_quote, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;DeriveInput&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Stmt&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Constructable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;FieldMut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;HasAttributes&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;NamedOrUnnamedFieldMut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Trait&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TraitItem&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;/// On the top structure&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;VISIT_SELF_NAME&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;visit_self&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;/// Per field modifiers&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;VISIT_SKIP_NAME&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;visit_skip_field&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;/// Add to chain. Can be on item or a field&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;VISIT_WITH_CHAIN_NAME&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;visit_with_chain&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;/// Usage #[derive(Visitable)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;#[proc_macro_derive(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Visitable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    attributes(visit_self, visit_skip_field, visit_custom_visit)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;generate_visit_implementation&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(input&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TokenStream&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TokenStream&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; input &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_macro_input!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(input &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;DeriveInput&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; visit_item &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TraitItem&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;new_method&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ident&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;visit&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;call_site&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;vec!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TData&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;syn_helpers&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeOfSelf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Reference&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;vec!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(visitors&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;impl&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;crate::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;visiting&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;VisitorReceiver&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TData&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Sized&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(data&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TData&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(settings&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;crate::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;VisitSettings&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;temporary_annex&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Annex&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;crate::&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;visiting&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Chain&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;generated_visit_item&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(item, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;VisitType&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Immutable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; visit_mut_item &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TraitItem&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;new_method&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ident&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;visit_mut&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;call_site&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;vec!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TData&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;syn_helpers&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TypeOfSelf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;MutableReference&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;vec!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(visitors&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;impl&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;crate::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;visiting&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;VisitorMutReceiver&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TData&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Sized&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(data&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;TData&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(settings&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;crate::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;VisitSettings&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;temporary_annex&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Annex&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;crate::&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;visiting&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Chain&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;generated_visit_item&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(item, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;VisitType&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Mutable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; visitable_trait &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Trait&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        name&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;crate::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;visiting&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Visitable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        generic_parameters&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        items&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;vec!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[visit_item, visit_mut_item],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; output &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;derive_trait&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(input, visitable_trait);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    output&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;into&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;#[derive(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Clone&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Copy&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;VisitType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Immutable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Mutable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;generated_visit_item&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;syn_helpers&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Item&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    visit_type&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;VisitType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Result&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Vec&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Stmt&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;dyn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Error&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; attributes &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;structure&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get_attributes&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; visit_self &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; attributes&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; attr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_ident&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;VISIT_SELF_NAME&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; visit_with_chain &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; attributes&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find_map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        attr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;path&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_ident&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;VISIT_WITH_CHAIN_NAME&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;then_some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;tokens)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; lines &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Vec&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(expr_tokens) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; visit_with_chain {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        lines&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; chain &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push_annex&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(#expr_tokens); ))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; visit_self {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; struct_name_as_snake_case &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;structure&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get_name&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;to_string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;to_snake_case&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; mut_postfix &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(visit_type, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;VisitType&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Mutable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;then_some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;_mut&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;unwrap_or_default&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; func_name &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;format_ident!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;visit_{}{}&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, struct_name_as_snake_case, mut_postfix);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        lines&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;( visitors&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func_name&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, data,  chain); ))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; field_lines &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;map_constructable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; constructable&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(constructable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get_fields_mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;fields_iterator_mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;flat_map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; field&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;NamedOrUnnamedFieldMut&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Stmt&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; attributes &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; field&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get_attributes&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; skip_field &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; attributes&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; attr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_ident&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;VISIT_SKIP_NAME&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; visit_with_chain &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; attributes&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;find_map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;					attr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_ident&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;VISIT_WITH_CHAIN_NAME&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;then_some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;tokens)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;				});&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; chain &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(expr_tokens) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; visit_with_chain {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;					&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; chain&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push_annex&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(#expr_tokens))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;				} &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;					&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(chain)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;				};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;skip_field {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;					&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; reference &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; field&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get_reference&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;					&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; visit_type {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;						&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;VisitType&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Immutable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;							&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;crate::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Visitable&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;visit&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(#reference, visitors, data, settings, #chain);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;						},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;						&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;VisitType&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Mutable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;							&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;crate::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Visitable&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;visit_mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(#reference, visitors, data, settings, #chain);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;						},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;					})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;				} &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;					&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;None&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;				}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;collect&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Vec&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;_&amp;gt;&amp;gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    })&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    lines&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; field_lines);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(lines)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;proc_macro&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TokenStream&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;std&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;error&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Error&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;string_cases&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;StringCasesExt&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;syn_helpers&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    derive_trait,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;proc_macro2&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ident&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;quote&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, format_ident},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;syn&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{parse_macro_input, parse_quote, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;DeriveInput&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Stmt&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Constructable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;FieldMut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;HasAttributes&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;NamedOrUnnamedFieldMut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Trait&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TraitItem&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;/// On the top structure&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;VISIT_SELF_NAME&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;visit_self&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;/// Per field modifiers&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;VISIT_SKIP_NAME&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;visit_skip_field&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;/// Add to chain. Can be on item or a field&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;VISIT_WITH_CHAIN_NAME&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;visit_with_chain&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;/// Usage #[derive(Visitable)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;#[proc_macro_derive(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Visitable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    attributes(visit_self, visit_skip_field, visit_custom_visit)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;generate_visit_implementation&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(input&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TokenStream&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TokenStream&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; input &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_macro_input!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(input &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;DeriveInput&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; visit_item &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TraitItem&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;new_method&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ident&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;visit&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;call_site&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;vec!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TData&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;syn_helpers&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeOfSelf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Reference&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;vec!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(visitors&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;impl&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;crate::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;visiting&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;VisitorReceiver&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TData&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Sized&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(data&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TData&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(settings&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;crate::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;VisitSettings&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;temporary_annex&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Annex&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;crate::&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;visiting&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Chain&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;generated_visit_item&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(item, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;VisitType&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Immutable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; visit_mut_item &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TraitItem&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;new_method&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ident&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;visit_mut&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;call_site&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;vec!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TData&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;syn_helpers&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TypeOfSelf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;MutableReference&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;vec!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(visitors&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;impl&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;crate::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;visiting&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;VisitorMutReceiver&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TData&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Sized&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(data&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;TData&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(settings&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;crate::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;VisitSettings&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;temporary_annex&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Annex&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;crate::&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;visiting&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Chain&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        ],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;generated_visit_item&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(item, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;VisitType&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Mutable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; visitable_trait &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Trait&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        name&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;crate::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;visiting&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Visitable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        generic_parameters&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        items&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;vec!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[visit_item, visit_mut_item],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; output &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;derive_trait&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(input, visitable_trait);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    output&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;into&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;#[derive(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Clone&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Copy&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;VisitType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Immutable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Mutable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;generated_visit_item&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;syn_helpers&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Item&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    visit_type&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;VisitType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Result&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Vec&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Stmt&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Box&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;dyn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Error&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; attributes &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;structure&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get_attributes&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; visit_self &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; attributes&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; attr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_ident&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;VISIT_SELF_NAME&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; visit_with_chain &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; attributes&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find_map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        attr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;path&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_ident&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;VISIT_WITH_CHAIN_NAME&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;then_some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;tokens)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; lines &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Vec&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(expr_tokens) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; visit_with_chain {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        lines&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; chain &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push_annex&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(#expr_tokens); ))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; visit_self {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; struct_name_as_snake_case &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;structure&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get_name&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;to_string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;to_snake_case&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; mut_postfix &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(visit_type, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;VisitType&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Mutable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;then_some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;_mut&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;unwrap_or_default&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; func_name &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;format_ident!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;visit_{}{}&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, struct_name_as_snake_case, mut_postfix);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        lines&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;( visitors&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func_name&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, data,  chain); ))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; field_lines &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;map_constructable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; constructable&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(constructable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get_fields_mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;fields_iterator_mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;flat_map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; field&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;NamedOrUnnamedFieldMut&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Stmt&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; attributes &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; field&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get_attributes&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; skip_field &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; attributes&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; attr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_ident&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;VISIT_SKIP_NAME&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; visit_with_chain &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; attributes&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;find_map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;					attr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_ident&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;VISIT_WITH_CHAIN_NAME&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;then_some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;attr&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;tokens)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;				});&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; chain &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(expr_tokens) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; visit_with_chain {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;					&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; chain&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push_annex&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(#expr_tokens))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;				} &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;					&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(chain)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;				};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;				&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;skip_field {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;					&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; reference &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; field&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get_reference&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;					&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Some&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; visit_type {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;						&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;VisitType&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Immutable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;							&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;crate::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Visitable&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;visit&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(#reference, visitors, data, settings, #chain);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;						},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;						&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;VisitType&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Mutable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;parse_quote!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;							&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;crate::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Visitable&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;visit_mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(#reference, visitors, data, settings, #chain);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;						},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;					})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;				} &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;					&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;None&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;				}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;collect&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Vec&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;_&amp;gt;&amp;gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    })&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    lines&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; field_lines);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(lines)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It takes around 140 lines to implement this trait. &lt;code&gt;syn-helpers&lt;/code&gt; here can handle the cases when the AST contains generics. Using &lt;code&gt;syn-helpers&lt;/code&gt; means the code can focus on the actual behaviour of the trait rather than handling all the different cases Rust declarations can be in.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Although it is called &lt;code&gt;syn-helpers&lt;/code&gt; and that was its original aim, it has now grown into a large framework focused on derive macros. So if you write derive macros and maybe struggle with keeping things concise. If you have API/abstraction you want to be added for a proc-macro you are writing I am open &lt;a href=&quot;https://github.com/kaleidawave/syn-helpers/issues&quot;&gt;for discussion&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Building this out I feel it might be close to a fully declarative macro implementation &lt;a href=&quot;https://github.com/kaleidawave/syn-helpers/issues/1&quot;&gt;notes here&lt;/a&gt;. Rust current has declarative macros but anything &lt;code&gt;derive&lt;/code&gt; based has to be done imperatively and there isn&#39;t an end-to-end declarative approach. Maybe it could be tried out in this library.&lt;/p&gt;
&lt;h3 id=&quot;putting-the-framework-to-build-more-customisable-derive-implementations&quot; tabindex=&quot;-1&quot;&gt;Putting the framework to build more customisable &lt;code&gt;derive&lt;/code&gt; implementations&lt;/h3&gt;
&lt;p&gt;I had written two macros before, and &lt;code&gt;syn-helpers&lt;/code&gt; &lt;em&gt;helped&lt;/em&gt; tidy up and share the code between these two. The two main ones are:&lt;/p&gt;
&lt;h3 id=&quot;%23%5Bderive(debugextras)%5D&quot; tabindex=&quot;-1&quot;&gt;&lt;code&gt;#[derive(DebugExtras)]&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;#[derive(Debug)]&lt;/code&gt; is great most times, but sometimes it lacks a bit of customisation for the derive item. &lt;a href=&quot;https://github.com/kaleidawave/derive-debug-extras&quot;&gt;derive-debug-extras&lt;/a&gt; offers an enhanced macro that adds &lt;code&gt;#[debug_ignore]&lt;/code&gt; and &lt;code&gt;#[debug_as_display]&lt;/code&gt; attributes that can help improve debugging.&lt;/p&gt;
&lt;p&gt;But arguably my favourite one is &lt;a href=&quot;https://github.com/kaleidawave/derive-debug-extras#debug_single_tuple_inline&quot;&gt;&lt;code&gt;#[debug_single_tuple_inline]&lt;/code&gt;&lt;/a&gt;. This fixes a problem in the Ezno checker. I use a lot of the new type pattern to declare identifiers. Unfortunately, despite them only having one field, when debugging them with the pretty flag (I want other named structs to be over lines) it ends up over three. So although it did require rewriting the standard debug implementation, now:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Without #[debug_single_tuple_inline]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;123&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;145&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;125&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// With #[debug_single_tuple_inline]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;123&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;145&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;125&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Without #[debug_single_tuple_inline]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;123&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;145&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;125&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// With #[debug_single_tuple_inline]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;123&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;145&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;125&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;IMO, all unnamed fields when debugged should be on one line despite the pretty flag.&lt;/p&gt;
&lt;h3 id=&quot;%23%5Bderive(partialeqextras)%5D&quot; tabindex=&quot;-1&quot;&gt;&lt;code&gt;#[derive(PartialEqExtras)]&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;In a similar vein, &lt;a href=&quot;https://github.com/kaleidawave/derive-partial-eq-extras&quot;&gt;derive-partial-eq-extras&lt;/a&gt; adds a more customisable &lt;a href=&quot;https://doc.rust-lang.org/std/cmp/trait.PartialEq.html&quot;&gt;PartialEq&lt;/a&gt; implementation. It adds two new attributes for ignoring certain fields in the implementer.&lt;/p&gt;
&lt;p&gt;For example, in my parser, expressions have positions and IDs. However, when comparing two expressions I want to treat them on a value basis and not based on position or identifiers. For example, given the literal expression &lt;code&gt;5&lt;/code&gt;, I want AST to equal other &lt;code&gt;5&lt;/code&gt;s, no matter where they have been parsed. To do this I simply add &lt;code&gt;#[partial_eq_ignore_types]&lt;/code&gt;, which I can use easily on the expression AST:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;#[derive(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PartialEqExtras&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Clone&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;#[partial_eq_ignore_types(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpressionId&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Expression&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;NumberLiteral&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;NumberStructure&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpressionId&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;StringLiteral&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, #[partial_eq_ignore] &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Quoted&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpressionId&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;BooleanLiteral&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpressionId&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;RegexLiteral&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		pattern&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		flags&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		position&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		id&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpressionId&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;ArrayLiteral&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Vec&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;SpreadExpression&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ExpressionId&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;ObjectLiteral&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ObjectLiteral&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;#[derive(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PartialEqExtras&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Clone&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;#[partial_eq_ignore_types(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpressionId&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Expression&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;NumberLiteral&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;NumberStructure&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpressionId&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;StringLiteral&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, #[partial_eq_ignore] &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Quoted&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpressionId&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;BooleanLiteral&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpressionId&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;RegexLiteral&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		pattern&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		flags&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		position&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		id&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpressionId&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;ArrayLiteral&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Vec&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;SpreadExpression&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ExpressionId&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;ObjectLiteral&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ObjectLiteral&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;This is similar to &lt;a href=&quot;https://docs.rs/educe/latest/educe/#ignore-fields-1&quot;&gt;educe&lt;/a&gt;, however it does not have the &lt;em&gt;ignore types&lt;/em&gt; feature, so declarations can get clobbered with annotations on lots of fields. I did try and add it to educe but got a bit scared by its codebase.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Again look into the sources and see that they are slim as they are built of &lt;code&gt;syn-helpers&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&quot;assisting-with-sum-enums&quot; tabindex=&quot;-1&quot;&gt;Assisting with sum &lt;code&gt;enum&lt;/code&gt;s&lt;/h2&gt;
&lt;p&gt;In the parser, I often have types that sum together some struct definitions like&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;#[derive(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Clone&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PartialEq&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Declaration&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Variable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;VariableDeclaration&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Decorated&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;StatementFunction&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Decorated&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ClassDeclaration&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;StatementPosition&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Enum&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Decorated&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;EnumDeclaration&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;#[derive(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Clone&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PartialEq&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Declaration&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Variable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;VariableDeclaration&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Decorated&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;StatementFunction&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Decorated&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ClassDeclaration&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;StatementPosition&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Enum&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Decorated&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;EnumDeclaration&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Converting in and out can be a bit of a pain. If I have a function that takes a &lt;code&gt;Declaration&lt;/code&gt; I need to remember the variant and then wrap the whole expression in it. So I created &lt;a href=&quot;https://github.com/kaleidawave/derive-enum-from-into&quot;&gt;derive enum from into&lt;/a&gt;. With this, I can add &lt;code&gt;#[derive(EnumFrom, EnumTryInto)]&lt;/code&gt; to have an easier time converting between the two (including immutable and mutable references).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;#[derive(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Clone&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;EnumFrom&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;EnumTryInto&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PartialEq&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;#[try_into_references(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Declaration&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Variable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;VariableDeclaration&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Decorated&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;StatementFunction&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Decorated&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ClassDeclaration&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;StatementPosition&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Enum&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Decorated&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;EnumDeclaration&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;my_func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(var_dec&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;VariableDeclaration&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; dec &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Declaration&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(var_dec);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assert!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(dec, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Declaration&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Variable&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(_)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; result &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Decorated&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;StatementFunction&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;try_from&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(dec);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assert!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(result&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;is_err&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;#[derive(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Clone&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;EnumFrom&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;EnumTryInto&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PartialEq&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;#[try_into_references(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Declaration&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Variable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;VariableDeclaration&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Decorated&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;StatementFunction&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Decorated&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ClassDeclaration&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;StatementPosition&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Enum&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Decorated&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;EnumDeclaration&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;my_func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(var_dec&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;VariableDeclaration&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; dec &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Declaration&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(var_dec);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assert!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;matches!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(dec, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Declaration&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Variable&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(_)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; result &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Decorated&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;StatementFunction&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;try_from&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(dec);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assert!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(result&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;is_err&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;This is a smaller, less configurable, &lt;code&gt;enum&lt;/code&gt; only version of &lt;a href=&quot;https://jeltef.github.io/derive_more/derive_more/from.html&quot;&gt;#[derive(From)] from the derive_more crate&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This crate is actually my most downloaded, possibly because it seems to be used on this &lt;a href=&quot;https://github.com/near/nearcore/blob/02bd5996d0e581f12768baa9f3f68849a77a8312/Cargo.toml#L121&quot;&gt;popular project&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;iterator-endiate&quot; tabindex=&quot;-1&quot;&gt;Iterator endiate&lt;/h2&gt;
&lt;p&gt;A smaller one, but I often have a case when iterating through something I want to know if it is the last one. This often happens in the to-string part of my parser where I want to add a comma delimiter between items but don&#39;t want a trailing comma. For &lt;a href=&quot;https://doc.rust-lang.org/stable/std/iter/trait.ExactSizeIterator.html&quot;&gt;iterators with a known size&lt;/a&gt;, this crate adds an &lt;a href=&quot;http://xion.io/post/code/rust-extension-traits.html&quot;&gt;extension trait&lt;/a&gt; that adds the &lt;code&gt;endiate&lt;/code&gt; method. Similar in functionality to the &lt;code&gt;enumerate&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// adds `.endiate()` method to all (sized) iterators&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;iterator_endiate&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;EndiateIteratorExt&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (at_end, item) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; items&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;endiate&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	settings&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;add_indent&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(depth, buf);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;to_string_from_buffer&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(buf, settings, depth);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;at_end {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;requires_semi_colon&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; settings&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;pretty {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;			buf&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push_new_line&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// adds `.endiate()` method to all (sized) iterators&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;iterator_endiate&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;EndiateIteratorExt&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (at_end, item) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; items&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;iter&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;endiate&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	settings&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;add_indent&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(depth, buf);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;to_string_from_buffer&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(buf, settings, depth);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;at_end {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;requires_semi_colon&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; settings&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;pretty {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;			buf&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push_new_line&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Also adds the &lt;code&gt;nendiate&lt;/code&gt; for when you want to know you are not at the end&lt;/p&gt;
&lt;h2 id=&quot;enums-and-strings&quot; tabindex=&quot;-1&quot;&gt;Enums and strings&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/enum-variants-strings&quot;&gt;Enum variants strings&lt;/a&gt; is a library for converting between (yes, both ways) &lt;code&gt;&amp;amp;str&lt;/code&gt; and &lt;code&gt;enum&lt;/code&gt; structures. The derive macro handles generating this based on variant names. Mapping from a string to an &lt;code&gt;enum&lt;/code&gt;, works for simple things that implement &lt;a href=&quot;https://doc.rust-lang.org/stable/std/default/trait.Default.html&quot;&gt;&lt;code&gt;Default&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;enum_variants_strings&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;EnumVariantsStrings&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;#[derive(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PartialEq&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;EnumVariantsStrings&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;i32&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    #[enum_variants_strings_mappings(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;z&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;zee&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        y&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assert_eq!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;from_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assert_eq!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;from_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;y&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assert_eq!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;from_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;z&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            y&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assert_eq!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;to_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assert_eq!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;abc&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;into&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            y&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;xyz&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;into&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;to_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;zee&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;enum_variants_strings&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;EnumVariantsStrings&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;#[derive(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PartialEq&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;EnumVariantsStrings&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;i32&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    #[enum_variants_strings_mappings(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;z&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;zee&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        y&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assert_eq!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;from_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assert_eq!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;from_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;y&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assert_eq!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;from_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;z&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            y&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assert_eq!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;to_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assert_eq!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Variants&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;abc&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;into&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            y&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;xyz&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;into&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;to_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;zee&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno/blob/75d31ddb60eee495915fcf805a56221d2e79ce7d/src/ast_explorer.rs#L40&quot;&gt;I use it for changing between modes in the ast-playground of Ezno&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;deploying-rust-with-github-actions&quot; tabindex=&quot;-1&quot;&gt;Deploying Rust with GitHub actions&lt;/h2&gt;
&lt;p&gt;In my crates, I want the update commit to automatically push the version change back to the repository. If I do it manually, I always forget to push after, things get out of sync.&lt;/p&gt;
&lt;p&gt;So I built a GitHub action for doing this: &lt;a href=&quot;https://github.com/kaleidawave/crates-release-gh-action&quot;&gt;crates-release-action&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here is how you can use it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;Release crate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;on&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;workflow_dispatch&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;description&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;major/minor/patch or semver&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;required&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;patch&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;concurrency&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;release-crate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;jobs&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;publish&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;runs-on&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;ubuntu-latest&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;steps&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;      - &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;uses&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;actions/checkout@v3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;      - &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;Set git credentials&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;run&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;          git config user.name github-actions&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;          git config user.email github-actions@github.com&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;      - &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;Crates publish&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;uses&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;kaleidawave/crates-release-gh-action@main&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;release&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;with&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;          &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;$&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;          &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;crates-token&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;$&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;      - &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;Push updated Cargo.toml&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;run&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;          git add .&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;          git commit -m &amp;quot;Release: $&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;          git tag &amp;quot;release/$&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;          git push --tags origin main&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;Release crate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;on&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;workflow_dispatch&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;inputs&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;description&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;major/minor/patch or semver&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;required&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;false&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;patch&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;concurrency&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;release-crate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #116329&quot;&gt;jobs&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;publish&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;runs-on&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;ubuntu-latest&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;steps&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;      - &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;uses&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;actions/checkout@v3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;      - &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;Set git credentials&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;run&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;          git config user.name github-actions&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;          git config user.email github-actions@github.com&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;      - &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;Crates publish&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;uses&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;kaleidawave/crates-release-gh-action@main&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;release&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;with&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;          &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;version&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;$&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;          &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;crates-token&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;$&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;      - &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;Push updated Cargo.toml&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;run&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;          git add .&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;          git commit -m &amp;quot;Release: $&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;          git tag &amp;quot;release/$&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;          git push --tags origin main&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It handles:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Finding manifests&lt;/li&gt;
&lt;li&gt;Applying &lt;code&gt;major&lt;/code&gt;, &lt;code&gt;minor&lt;/code&gt; or &lt;code&gt;patch&lt;/code&gt; to a version (or an exact version) and updating the contents of &lt;code&gt;Cargo.toml&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Finding local manifests that reference it as a path dependency to update their version&lt;/li&gt;
&lt;li&gt;Publishing to &lt;a href=&quot;https://crates.io/&quot;&gt;crates.io&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Outputting the new version(s) in a machine-readable format (so it can be referenced in commit names and tags)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can run it through &lt;a href=&quot;https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow&quot;&gt;github.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/demos/github-publish-crate-ui.png&quot; alt=&quot;GitHub publish crate UI&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Or from the command line with &lt;a href=&quot;https://cli.github.com/&quot;&gt;gh&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;video src=&quot;https://kaleidawave.github.io/media/demos/crates-gh-push.mp4&quot; controls=&quot;&quot; title=&quot;Crates GH push&quot;&gt;&lt;/video&gt;&lt;/p&gt;
&lt;p&gt;Which I can watch&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/demos/github-publish-crate-cl-watch.png&quot; alt=&quot;GitHub publish crate watch&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Behind the scenes, it updates the packages in the order of least dependency (I don&#39;t want to rely on myself for ordering arguments, &lt;a href=&quot;https://github.com/kaleidawave/crates-release-gh-action/blob/4dd293538aec8fc068acf08f35e60c0d015b7547/updater.py#L54-L66&quot;&gt;it can be calculated&lt;/a&gt;). It also uses a TOML parser that retains the TOML formatting. It is currently written in Python. If anyone wants to rewrite it in Rust and/or add more functionality, LMK!&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;It is a manual action currently, and isn&#39;t particularly automated. It doesn&#39;t track changes in a workspace, or figure out &lt;em&gt;Semver&lt;/em&gt; or build changelogs. I want the base to be simple and un-opinionated&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;
&lt;p&gt;I didn&#39;t have space but two more crates I have made are: &lt;a href=&quot;https://crates.io/crates/multiline-term-input&quot;&gt;multiline-term-input&lt;/a&gt;, which is a way to break into new lines during console input (&lt;a href=&quot;https://github.com/kaleidawave/multiline-term-input/issues/1&quot;&gt;I need a wiz to add Linux support&lt;/a&gt;) and &lt;a href=&quot;https://crates.io/crates/temporary-annex&quot;&gt;temporary-annex&lt;/a&gt; that helps to work with appending data temporarily while reusing &lt;strong&gt;the same&lt;/strong&gt; backing (linear) buffer.&lt;/p&gt;
&lt;p&gt;And that is all. If you have built or used any cool Rust libraries or additional tools let me know in the comments!&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Ezno in &#39;23</title>
    <link href="https://kaleidawave.github.io/posts/ezno-23/"/>
    <updated>2023-01-18T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/ezno-23/</id>
    <summary>Where is Ezno? What&#39;s next?</summary>
    <content xml:lang="en" type="html">&lt;p&gt;It&#39;s been a minute since the previous announcement so I thought would give some updates and share some upcoming problems. This follows the initial announcement and includes some smaller things I &lt;a href=&quot;https://twitter.com/kaleidawave&quot;&gt;shared on Twitter&lt;/a&gt; since the announcement post.&lt;/p&gt;
&lt;p&gt;Never heard of Ezno? It is a parser, partial executor, optimizer and type checker for JavaScript! &lt;a href=&quot;https://kaleidawave.github.io/posts/introducing-ezno&quot;&gt;Read the initial announcement&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;new-changes&quot; tabindex=&quot;-1&quot;&gt;New changes&lt;/h2&gt;
&lt;h3 id=&quot;classes%2C-getters-and-setters&quot; tabindex=&quot;-1&quot;&gt;Classes, getters and setters&lt;/h3&gt;
&lt;p&gt;I added support for classes, getters and setters&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/class-01.png&quot; alt=&quot;Handling of classes&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This required some changes to the definition of types and how they handle prototypes. I also added handling for the cases when a property is a getter or setter when doing property access and assignments. This addition also added support for getters and setters in object literals.&lt;/p&gt;
&lt;h4 id=&quot;tree-shaking-methods&quot; tabindex=&quot;-1&quot;&gt;Tree shaking methods&lt;/h4&gt;
&lt;p&gt;When adding classes I extended the tree-shaking mechanism (present but not mentioned in the announcement post) to class methods. Because of object tracing and call detection, if a method on a class is never called then the code is never included in the output.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/class-tree-shaking-01.png&quot; alt=&quot;Input&quot; class=&quot;invertible&quot; /&gt;
&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/class-tree-shaking-02.png&quot; alt=&quot;Output&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This is one of the reasons for not following TypeScript&#39;s rules around &lt;code&gt;any&lt;/code&gt;. If even a single call like &lt;code&gt;(x as any)[&amp;quot;method&amp;quot; as any]()&lt;/code&gt; was treated with type annotations being the source of truth then any sort of method removal could remove called code.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The perhaps underrated benefit here it is not just class code being removed, it is all functions that might be referenced in a class method that can now be removed.&lt;/strong&gt;&lt;/p&gt;
&lt;h4 id=&quot;custom-element-registration-event&quot; tabindex=&quot;-1&quot;&gt;Custom element registration event&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/class-custom-elements.png&quot; alt=&quot;Output&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Putting aside any of my opinions on custom elements. Calling &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define&quot;&gt;&lt;code&gt;CustomElementRegistry.define()&lt;/code&gt;&lt;/a&gt; results in running an effect that adds a mapping to the &lt;a href=&quot;https://github.com/microsoft/TypeScript/blob/9c9d4b029d71fc6b56598b0ff201c2a271c31c06/lib/lib.dom.d.ts#L17630&quot;&gt;&lt;code&gt;HTMLElementTagNameMap&lt;/code&gt;&lt;/a&gt; type and thus can get type safety in some more tricky scenarios.&lt;/p&gt;
&lt;h3 id=&quot;a-repl&quot; tabindex=&quot;-1&quot;&gt;A REPL&lt;/h3&gt;
&lt;p&gt;A REPL (read evaluate print loop) is an interactive code executor. Similar to &lt;a href=&quot;https://www.npmjs.com/package/ts-node&quot;&gt;ts-node&lt;/a&gt;, the Ezno REPL wraps an existing REPL with a checker. This required a few changes and while still a long way from perfect the checker can do a little more incrementally.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/repl-01.png&quot; alt=&quot;REPL in eval mode&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;p&gt;There is also a mode that prints the type output.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/repl-02.png&quot; alt=&quot;REPL in type mode&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This is mostly to help me with debugging what Ezno does. But maybe it will be useful generally for working out the arguments for functions etc.&lt;/p&gt;
&lt;p&gt;You can see the &lt;a href=&quot;https://gist.github.com/kaleidawave/807747b31458bad6540da976529c4d3d&quot;&gt;wrapper code for Deno here&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&quot;the-satisfies-operator&quot; tabindex=&quot;-1&quot;&gt;The &lt;code&gt;satisfies&lt;/code&gt; operator&lt;/h4&gt;
&lt;p&gt;There are two interesting things I slipped into the first code snippet that ran in the REPL.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The first was a divides operator. I was just playing around, it won&#39;t be in the published tool. 😀&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The second one is revealed if you try &lt;a href=&quot;https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgCoE9kG9kAcoD2uAXMgM5hSgDmyAPsiAK4C2ARtMgL4CwAUPwQEQFZAA9SGZAF5seQiWQBmbgG5+g4aMyyAsnDAALAHS4CAdwAUY0woA0yAEwBKZAGpkADlVA&quot;&gt;running the code in TSC&lt;/a&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;I was recently asked whether Ezno supported the recent TypeScript addition, the &lt;code&gt;satisfies&lt;/code&gt; operator. The &lt;code&gt;satisfies&lt;/code&gt; binary operator is a compile-time assertion that the left expression operand is typeable under the right type reference operand. It has almost identical behaviour to the &lt;code&gt;assertType&lt;/code&gt; identity function trick that was shown in the original announcement.&lt;/p&gt;
&lt;p&gt;The existence of this piece of syntax seems to be handling a problem that occurs with variable declarations in TypeScript. With the statement &lt;code&gt;let x: A = b&lt;/code&gt;, variable reference &lt;code&gt;x&lt;/code&gt; is considered to have all the properties of type &lt;code&gt;A&lt;/code&gt;. While that is fine and how every nominal type system works, it can cause problems when &lt;code&gt;A&lt;/code&gt; is a larger type than the type of &lt;code&gt;b&lt;/code&gt; and loses some properties.&lt;/p&gt;
&lt;p&gt;In the code shown in the REPL, TS treats &lt;code&gt;x.prop&lt;/code&gt; as &lt;code&gt;string | number&lt;/code&gt;. However looking at the code it is clear that the &lt;code&gt;x.prop&lt;/code&gt; is a number at the point of the &lt;code&gt;Math.pow&lt;/code&gt; call, never a &lt;code&gt;string&lt;/code&gt;. What &lt;code&gt;satisfies&lt;/code&gt; allows for is checking without &lt;em&gt;widening&lt;/em&gt; the type (as widening loses information).&lt;/p&gt;
&lt;p&gt;So how does this check under Ezno? Although &lt;code&gt;Math.pow&lt;/code&gt; can take a string argument in JS, it is typed as &lt;code&gt;(a: number, b: number) =&amp;gt; number;&lt;/code&gt;. So it has approved &lt;code&gt;x.prop&lt;/code&gt; as a number.&lt;/p&gt;
&lt;p&gt;In Ezno variables have two pieces of type data attached to them:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A &lt;em&gt;current&lt;/em&gt; value&lt;/li&gt;
&lt;li&gt;A space the value can operate in (defined using the variable type annotation)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;The current value type is used when checking usage and the space type is used when checking reassignments.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/reassignment-diagram.png&quot; alt=&quot;reassignments&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Therefore the &lt;code&gt;Math.pow&lt;/code&gt; call checks &lt;code&gt;x&lt;/code&gt; using the current value (which is a number here). It does not use the reassignment constraint.&lt;/p&gt;
&lt;p&gt;This was present early in Ezno (before I had heard of the &lt;code&gt;satisfies&lt;/code&gt; operator). This behaviour was needed to be able to detect dead code here:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;bigFunction&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;bigFunction&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The problem I have with satisfies is that isn&#39;t a drop in replacement. There doesn&#39;t seem to be a way to retain the value information while constraining variable value for reassignment. That is something that is the default with Ezno&#39;s point-in-a-space system.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;I am glad that TypeScript is pursuing more into dependent/literal types checking. And I can see why variable declarations are checked that way in TSC. Ezno&#39;s implementation only works because of effect tracking, which allows it to identify variable mutations from functions. Effect tracking is tricky to do (as will be shown later), so I understand why TypeScript doesn&#39;t do it.&lt;/p&gt;
&lt;p&gt;So &lt;code&gt;satisfies&lt;/code&gt; doesn&#39;t have any effect on checking in Ezno. Similarly things like &lt;code&gt;as const&lt;/code&gt; don&#39;t help Ezno. They don&#39;t have any effect on the system as it is all inferred or treated computationally.&lt;/p&gt;
&lt;p&gt;Is there a limit to how much TypeScript can tighten up by adding additional syntax? Does Ezno&#39;s effect tracking make it more approachable for beginners?&lt;/p&gt;
&lt;h3 id=&quot;binary-context%2Fdefinition-files&quot; tabindex=&quot;-1&quot;&gt;Binary context/definition files&lt;/h3&gt;
&lt;p&gt;I added a binary serialized form of contexts just before the announcement went up but didn&#39;t have a lot of space to include it. These are an alternative form to &lt;code&gt;.d.ts&lt;/code&gt; files and are more compact and include direct references to the identifiers used in Ezno.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/binary-context-01.png&quot; alt=&quot;Hex dump of binary&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;p&gt;In TSC cold start time is not great. One of the bottlenecks (I think) for performance, is the parsing and synthesizing initial contexts stage. Definition files are large, contain lots of unused information in terms of comments (only useful when using TSC in LSP mode) and are a format that is intensive to parse. On the other hand, Ezno&#39;s additional low-level byte definition files (that can be generated from an existing context) can be synthesized without having to build up an abstract syntax tree and are much smaller with no whitespace and extracted comments. The format is split up the same way the data structures are arranged in the checker. Regular definition files are dense with information, the binary form has sections for type name mapping, variable mapping, function types, etc which could be processed in parallel for further improvement.&lt;/p&gt;
&lt;p&gt;These results are only for &lt;code&gt;simple.d.ts&lt;/code&gt; which is a subset of the declarations in &lt;code&gt;lib.d.ts&lt;/code&gt;. It&#39;s about 6x times smaller as it only includes the definitions that Ezno currently understands. However, the benefits are looking promising at around ~14x faster creating initial contexts:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-shell&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Parsing .d.ts: 4.4306ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Synthesizing .d.ts: 10.4137ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Reading from binary 988.5μs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Parsing .d.ts: 4.4306ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Synthesizing .d.ts: 10.4137ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Reading from binary 988.5μs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;One of the benefits of being written in Rust &lt;svg class=&quot;icon&quot; viewBox=&quot;0 0 24 24&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M23.8346 11.7033l-1.0073-.6236a13.7268 13.7268 0 00-.0283-.2936l.8656-.8069a.3483.3483 0 00-.1154-.578l-1.1066-.414a8.4958 8.4958 0 00-.087-.2856l.6904-.9587a.3462.3462 0 00-.2257-.5446l-1.1663-.1894a9.3574 9.3574 0 00-.1407-.2622l.49-1.0761a.3437.3437 0 00-.0274-.3361.3486.3486 0 00-.3006-.154l-1.1845.0416a6.7444 6.7444 0 00-.1873-.2268l.2723-1.153a.3472.3472 0 00-.417-.4172l-1.1532.2724a14.0183 14.0183 0 00-.2278-.1873l.0415-1.1845a.3442.3442 0 00-.49-.328l-1.076.491c-.0872-.0476-.1742-.0952-.2623-.1407l-.1903-1.1673A.3483.3483 0 0016.256.955l-.9597.6905a8.4867 8.4867 0 00-.2855-.086l-.414-1.1066a.3483.3483 0 00-.5781-.1154l-.8069.8666a9.2936 9.2936 0 00-.2936-.0284L12.2946.1683a.3462.3462 0 00-.5892 0l-.6236 1.0073a13.7383 13.7383 0 00-.2936.0284L9.9803.3374a.3462.3462 0 00-.578.1154l-.4141 1.1065c-.0962.0274-.1903.0567-.2855.086L7.744.955a.3483.3483 0 00-.5447.2258L7.009 2.348a9.3574 9.3574 0 00-.2622.1407l-1.0762-.491a.3462.3462 0 00-.49.328l.0416 1.1845a7.9826 7.9826 0 00-.2278.1873L3.8413 3.425a.3472.3472 0 00-.4171.4171l.2713 1.1531c-.0628.075-.1255.1509-.1863.2268l-1.1845-.0415a.3462.3462 0 00-.328.49l.491 1.0761a9.167 9.167 0 00-.1407.2622l-1.1662.1894a.3483.3483 0 00-.2258.5446l.6904.9587a13.303 13.303 0 00-.087.2855l-1.1065.414a.3483.3483 0 00-.1155.5781l.8656.807a9.2936 9.2936 0 00-.0283.2935l-1.0073.6236a.3442.3442 0 000 .5892l1.0073.6236c.008.0982.0182.1964.0283.2936l-.8656.8079a.3462.3462 0 00.1155.578l1.1065.4141c.0273.0962.0567.1914.087.2855l-.6904.9587a.3452.3452 0 00.2268.5447l1.1662.1893c.0456.088.0922.1751.1408.2622l-.491 1.0762a.3462.3462 0 00.328.49l1.1834-.0415c.0618.0769.1235.1528.1873.2277l-.2713 1.1541a.3462.3462 0 00.4171.4161l1.153-.2713c.075.0638.151.1255.2279.1863l-.0415 1.1845a.3442.3442 0 00.49.327l1.0761-.49c.087.0486.1741.0951.2622.1407l.1903 1.1662a.3483.3483 0 00.5447.2268l.9587-.6904a9.299 9.299 0 00.2855.087l.414 1.1066a.3452.3452 0 00.5781.1154l.8079-.8656c.0972.0111.1954.0203.2936.0294l.6236 1.0073a.3472.3472 0 00.5892 0l.6236-1.0073c.0982-.0091.1964-.0183.2936-.0294l.8069.8656a.3483.3483 0 00.578-.1154l.4141-1.1066a8.4626 8.4626 0 00.2855-.087l.9587.6904a.3452.3452 0 00.5447-.2268l.1903-1.1662c.088-.0456.1751-.0931.2622-.1407l1.0762.49a.3472.3472 0 00.49-.327l-.0415-1.1845a6.7267 6.7267 0 00.2267-.1863l1.1531.2713a.3472.3472 0 00.4171-.416l-.2713-1.1542c.0628-.0749.1255-.1508.1863-.2278l1.1845.0415a.3442.3442 0 00.328-.49l-.49-1.076c.0475-.0872.0951-.1742.1407-.2623l1.1662-.1893a.3483.3483 0 00.2258-.5447l-.6904-.9587.087-.2855 1.1066-.414a.3462.3462 0 00.1154-.5781l-.8656-.8079c.0101-.0972.0202-.1954.0283-.2936l1.0073-.6236a.3442.3442 0 000-.5892zm-6.7413 8.3551a.7138.7138 0 01.2986-1.396.714.714 0 11-.2997 1.396zm-.3422-2.3142a.649.649 0 00-.7715.5l-.3573 1.6685c-1.1035.501-2.3285.7795-3.6193.7795a8.7368 8.7368 0 01-3.6951-.814l-.3574-1.6684a.648.648 0 00-.7714-.499l-1.473.3158a8.7216 8.7216 0 01-.7613-.898h7.1676c.081 0 .1356-.0141.1356-.088v-2.536c0-.074-.0536-.0881-.1356-.0881h-2.0966v-1.6077h2.2677c.2065 0 1.1065.0587 1.394 1.2088.0901.3533.2875 1.5044.4232 1.8729.1346.413.6833 1.2381 1.2685 1.2381h3.5716a.7492.7492 0 00.1296-.0131 8.7874 8.7874 0 01-.8119.9526zM6.8369 20.024a.714.714 0 11-.2997-1.396.714.714 0 01.2997 1.396zM4.1177 8.9972a.7137.7137 0 11-1.304.5791.7137.7137 0 011.304-.579zm-.8352 1.9813l1.5347-.6824a.65.65 0 00.33-.8585l-.3158-.7147h1.2432v5.6025H3.5669a8.7753 8.7753 0 01-.2834-3.348zm6.7343-.5437V8.7836h2.9601c.153 0 1.0792.1772 1.0792.8697 0 .575-.7107.7815-1.2948.7815zm10.7574 1.4862c0 .2187-.008.4363-.0243.651h-.9c-.09 0-.1265.0586-.1265.1477v.413c0 .973-.5487 1.1846-1.0296 1.2382-.4576.0517-.9648-.1913-1.0275-.4717-.2704-1.5186-.7198-1.8436-1.4305-2.4034.8817-.5599 1.799-1.386 1.799-2.4915 0-1.1936-.819-1.9458-1.3769-2.3153-.7825-.5163-1.6491-.6195-1.883-.6195H5.4682a8.7651 8.7651 0 014.907-2.7699l1.0974 1.151a.648.648 0 00.9182.0213l1.227-1.1743a8.7753 8.7753 0 016.0044 4.2762l-.8403 1.8982a.652.652 0 00.33.8585l1.6178.7188c.0283.2875.0425.577.0425.8717zm-9.3006-9.5993a.7128.7128 0 11.984 1.0316.7137.7137 0 01-.984-1.0316zm8.3389 6.71a.7107.7107 0 01.9395-.3625.7137.7137 0 11-.9405.3635z&quot;&gt;&lt;/path&gt;&lt;/svg&gt; is that dealing with low-level byte processing and access is nice and simple!&lt;/p&gt;
&lt;p&gt;Still unsure how the distribution of these will work. Also currently it only supports root contexts, haven&#39;t figured source splitting and referencing for child contexts yet.&lt;/p&gt;
&lt;h2 id=&quot;upcoming-changes&quot; tabindex=&quot;-1&quot;&gt;Upcoming changes&lt;/h2&gt;
&lt;p&gt;Here I some things I am going to start tackling over the next couple of months. They all relate to effects.&lt;/p&gt;
&lt;h3 id=&quot;internal-object-effects&quot; tabindex=&quot;-1&quot;&gt;Internal object effects&lt;/h3&gt;
&lt;p&gt;One of the upcoming problems to solve is arrays and mutations.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;x.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (x.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;at&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;Hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;x.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (x.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;at&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;Hi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here &lt;code&gt;.push&lt;/code&gt; mutates &lt;code&gt;x&lt;/code&gt;. Just looking at the TS definition for the method, &lt;code&gt;push(...items: T[]): number&lt;/code&gt;, it doesn&#39;t give much information about what it does. Without knowing what &lt;code&gt;.push&lt;/code&gt; mutates the &lt;code&gt;x.get(-1)&lt;/code&gt; call can&#39;t return accurate information. If it did know, the checker could find &lt;code&gt;4 !== 4&lt;/code&gt; is always false and the if branch never fires.&lt;/p&gt;
&lt;p&gt;Therefore the type declaration needs to include more information. Currently, this is done using decorators on the method declaration, which Ezno interprets specially. However, there may be a more descriptive way to register this information:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	@&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Effects&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;sets [this.length] on this to T&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;sets &amp;#39;length&amp;#39; on this to Add&amp;lt;this[&amp;#39;length&amp;#39;], 1&amp;gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Add&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;length&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;], &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Maybe it is more readable to do something like&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) performs {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; t;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	@&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Effects&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;sets [this.length] on this to T&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;sets &amp;#39;length&amp;#39; on this to Add&amp;lt;this[&amp;#39;length&amp;#39;], 1&amp;gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Add&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;length&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;], &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Maybe it is more readable to do something like&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) performs {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; t;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This shouldn&#39;t be impossible to add to declarations. There isn&#39;t a huge amount in the standard library and not a huge amount in DOM API. It isn&#39;t a hugely complex task for these to be added but is very beneficial.&lt;/p&gt;
&lt;h3 id=&quot;asynchronous-effects&quot; tabindex=&quot;-1&quot;&gt;Asynchronous effects&lt;/h3&gt;
&lt;p&gt;There are several different types of effects. One is modifying a variable (or property), this fixes several problems with &lt;a href=&quot;https://github.com/microsoft/TypeScript/issues/9998&quot;&gt;issues with control flow analysis in TypeScript&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;So far synchronous situations are covered:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(() &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(x);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(() &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(x);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Asynchronous code (where the order of execution isn&#39;t trivial) is next to implement:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;setTimeout&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(() &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;; }, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Function will be called but not until it has reached a point where the event loop runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(x)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;setTimeout&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(() &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;; }, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Function will be called but not until it has reached a point where the event loop runs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(x)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To support this, it shouldn&#39;t be too difficult:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Determining when functions are queued or registered to an event loop (such as &lt;code&gt;setTimeout&lt;/code&gt;, &lt;code&gt;addEventListener&lt;/code&gt;) vs immediately called (such as in &lt;code&gt;Array.prototype.map&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Running function effects at the end of synchronisation. Whether that is the end of the script or some &lt;code&gt;await&lt;/code&gt; expressions.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;handling-errors&quot; tabindex=&quot;-1&quot;&gt;Handling errors&lt;/h3&gt;
&lt;p&gt;In TS, functions that throw can be typed using a return type of &lt;code&gt;never&lt;/code&gt;. However, there is no information in the type system to depict what type is thrown. In Ezno &lt;code&gt;throw&lt;/code&gt; statements current queue special &lt;code&gt;throw&lt;/code&gt; effects. There are two things left before this system becomes usable:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Expressions that always throw and are not in a catch-able structure should produce an error&lt;/li&gt;
&lt;li&gt;In a try-catch statement, the checker needs to collect possible objects thrown to form a type of &lt;code&gt;err&lt;/code&gt; in &lt;code&gt;catch (err)&lt;/code&gt;. This makes catch branches TypeSafe™. Or alternatively, if no throw effects in the try block the checker should emit a warning.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And in code that is generic:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;safeEval&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; () &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;try&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	} &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;catch&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (err) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(err.message)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;safeEval&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; () &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;try&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	} &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;catch&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (err) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(err.message)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There needs to exist a &lt;code&gt;Thrown&amp;lt;T&amp;gt;&lt;/code&gt; internal helper type that can extract what is thrown from a function.&lt;/p&gt;
&lt;h2 id=&quot;is-it-open-source%3F-where&#39;s-the-binary%3F&quot; tabindex=&quot;-1&quot;&gt;Is it open source? Where&#39;s the binary?&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno&quot;&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;, Ezno is now open-source&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Open source is more than switching a GitHub repo from private to public. IMO large public repositories should have some sort of stable roadmap or design that contributors can follow. Time needs to be put in to follow issues through. And currently, for the checker, I don&#39;t have any of that soo. I think it will be best if it is incrementally made public. The parser is nearly at a point I would consider publishable so hopefully there will be a release soon!&lt;/p&gt;
&lt;p&gt;In terms of the executable binary, I want to release it when it can check an actual useful program. Once the above issues with effects are solved then, it will open up more real-world demos. After then, it should be good to go!&lt;/p&gt;
&lt;h3 id=&quot;other-things-coming-up&quot; tabindex=&quot;-1&quot;&gt;Other things coming up&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;I work on a few other &lt;a href=&quot;https://crates.io/users/kaleidawave?sort=recent-updates&quot;&gt;crates&lt;/a&gt;. Some of those will be getting updates soon.&lt;/li&gt;
&lt;li&gt;I have two posts coming out soon about Rust &lt;svg class=&quot;icon&quot; viewBox=&quot;0 0 24 24&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M23.8346 11.7033l-1.0073-.6236a13.7268 13.7268 0 00-.0283-.2936l.8656-.8069a.3483.3483 0 00-.1154-.578l-1.1066-.414a8.4958 8.4958 0 00-.087-.2856l.6904-.9587a.3462.3462 0 00-.2257-.5446l-1.1663-.1894a9.3574 9.3574 0 00-.1407-.2622l.49-1.0761a.3437.3437 0 00-.0274-.3361.3486.3486 0 00-.3006-.154l-1.1845.0416a6.7444 6.7444 0 00-.1873-.2268l.2723-1.153a.3472.3472 0 00-.417-.4172l-1.1532.2724a14.0183 14.0183 0 00-.2278-.1873l.0415-1.1845a.3442.3442 0 00-.49-.328l-1.076.491c-.0872-.0476-.1742-.0952-.2623-.1407l-.1903-1.1673A.3483.3483 0 0016.256.955l-.9597.6905a8.4867 8.4867 0 00-.2855-.086l-.414-1.1066a.3483.3483 0 00-.5781-.1154l-.8069.8666a9.2936 9.2936 0 00-.2936-.0284L12.2946.1683a.3462.3462 0 00-.5892 0l-.6236 1.0073a13.7383 13.7383 0 00-.2936.0284L9.9803.3374a.3462.3462 0 00-.578.1154l-.4141 1.1065c-.0962.0274-.1903.0567-.2855.086L7.744.955a.3483.3483 0 00-.5447.2258L7.009 2.348a9.3574 9.3574 0 00-.2622.1407l-1.0762-.491a.3462.3462 0 00-.49.328l.0416 1.1845a7.9826 7.9826 0 00-.2278.1873L3.8413 3.425a.3472.3472 0 00-.4171.4171l.2713 1.1531c-.0628.075-.1255.1509-.1863.2268l-1.1845-.0415a.3462.3462 0 00-.328.49l.491 1.0761a9.167 9.167 0 00-.1407.2622l-1.1662.1894a.3483.3483 0 00-.2258.5446l.6904.9587a13.303 13.303 0 00-.087.2855l-1.1065.414a.3483.3483 0 00-.1155.5781l.8656.807a9.2936 9.2936 0 00-.0283.2935l-1.0073.6236a.3442.3442 0 000 .5892l1.0073.6236c.008.0982.0182.1964.0283.2936l-.8656.8079a.3462.3462 0 00.1155.578l1.1065.4141c.0273.0962.0567.1914.087.2855l-.6904.9587a.3452.3452 0 00.2268.5447l1.1662.1893c.0456.088.0922.1751.1408.2622l-.491 1.0762a.3462.3462 0 00.328.49l1.1834-.0415c.0618.0769.1235.1528.1873.2277l-.2713 1.1541a.3462.3462 0 00.4171.4161l1.153-.2713c.075.0638.151.1255.2279.1863l-.0415 1.1845a.3442.3442 0 00.49.327l1.0761-.49c.087.0486.1741.0951.2622.1407l.1903 1.1662a.3483.3483 0 00.5447.2268l.9587-.6904a9.299 9.299 0 00.2855.087l.414 1.1066a.3452.3452 0 00.5781.1154l.8079-.8656c.0972.0111.1954.0203.2936.0294l.6236 1.0073a.3472.3472 0 00.5892 0l.6236-1.0073c.0982-.0091.1964-.0183.2936-.0294l.8069.8656a.3483.3483 0 00.578-.1154l.4141-1.1066a8.4626 8.4626 0 00.2855-.087l.9587.6904a.3452.3452 0 00.5447-.2268l.1903-1.1662c.088-.0456.1751-.0931.2622-.1407l1.0762.49a.3472.3472 0 00.49-.327l-.0415-1.1845a6.7267 6.7267 0 00.2267-.1863l1.1531.2713a.3472.3472 0 00.4171-.416l-.2713-1.1542c.0628-.0749.1255-.1508.1863-.2278l1.1845.0415a.3442.3442 0 00.328-.49l-.49-1.076c.0475-.0872.0951-.1742.1407-.2623l1.1662-.1893a.3483.3483 0 00.2258-.5447l-.6904-.9587.087-.2855 1.1066-.414a.3462.3462 0 00.1154-.5781l-.8656-.8079c.0101-.0972.0202-.1954.0283-.2936l1.0073-.6236a.3442.3442 0 000-.5892zm-6.7413 8.3551a.7138.7138 0 01.2986-1.396.714.714 0 11-.2997 1.396zm-.3422-2.3142a.649.649 0 00-.7715.5l-.3573 1.6685c-1.1035.501-2.3285.7795-3.6193.7795a8.7368 8.7368 0 01-3.6951-.814l-.3574-1.6684a.648.648 0 00-.7714-.499l-1.473.3158a8.7216 8.7216 0 01-.7613-.898h7.1676c.081 0 .1356-.0141.1356-.088v-2.536c0-.074-.0536-.0881-.1356-.0881h-2.0966v-1.6077h2.2677c.2065 0 1.1065.0587 1.394 1.2088.0901.3533.2875 1.5044.4232 1.8729.1346.413.6833 1.2381 1.2685 1.2381h3.5716a.7492.7492 0 00.1296-.0131 8.7874 8.7874 0 01-.8119.9526zM6.8369 20.024a.714.714 0 11-.2997-1.396.714.714 0 01.2997 1.396zM4.1177 8.9972a.7137.7137 0 11-1.304.5791.7137.7137 0 011.304-.579zm-.8352 1.9813l1.5347-.6824a.65.65 0 00.33-.8585l-.3158-.7147h1.2432v5.6025H3.5669a8.7753 8.7753 0 01-.2834-3.348zm6.7343-.5437V8.7836h2.9601c.153 0 1.0792.1772 1.0792.8697 0 .575-.7107.7815-1.2948.7815zm10.7574 1.4862c0 .2187-.008.4363-.0243.651h-.9c-.09 0-.1265.0586-.1265.1477v.413c0 .973-.5487 1.1846-1.0296 1.2382-.4576.0517-.9648-.1913-1.0275-.4717-.2704-1.5186-.7198-1.8436-1.4305-2.4034.8817-.5599 1.799-1.386 1.799-2.4915 0-1.1936-.819-1.9458-1.3769-2.3153-.7825-.5163-1.6491-.6195-1.883-.6195H5.4682a8.7651 8.7651 0 014.907-2.7699l1.0974 1.151a.648.648 0 00.9182.0213l1.227-1.1743a8.7753 8.7753 0 016.0044 4.2762l-.8403 1.8982a.652.652 0 00.33.8585l1.6178.7188c.0283.2875.0425.577.0425.8717zm-9.3006-9.5993a.7128.7128 0 11.984 1.0316.7137.7137 0 01-.984-1.0316zm8.3389 6.71a.7107.7107 0 01.9395-.3625.7137.7137 0 11-.9405.3635z&quot;&gt;&lt;/path&gt;&lt;/svg&gt; and procedural macros.&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title>Introducing Ezno</title>
    <link href="https://kaleidawave.github.io/posts/introducing-ezno/"/>
    <updated>2022-09-22T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/introducing-ezno/</id>
    <summary>Introducing Ezno and the current state of the project.</summary>
    <content xml:lang="en" type="html">&lt;p&gt;Ezno is an experimental compiler I have been working on and off for a while. &lt;strong&gt;In short, it is a JavaScript compiler featuring checking, correctness and performance for building full-stack (rendering on the client and server) websites&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This post is just an overview of some of the features I have been working on which I think are quite cool as well an overview on the project philosophy ;)&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;It is still work in progress, all the examples work but the tool is still in its infancy&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1 id=&quot;type-synthesis-and-checking&quot; tabindex=&quot;-1&quot;&gt;Type synthesis and checking&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;The core of Ezno is a type checker for JavaScript&lt;/strong&gt;. Type synthesis is analysing syntax and formulating properties of terms. Comparing the information on terms and how those terms are used, a type checker can prevent errors at runtime.&lt;/p&gt;
&lt;p class=&quot;invertible&quot;&gt;&lt;video src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/ezno-lsp.webm&quot; controls=&quot;&quot; title=&quot;Ezno LSP&quot;&gt;&lt;/video&gt;&lt;/p&gt;
&lt;p&gt;Ezno&#39;s type checker is built from scratch. Getting the features I wanted required a lot of different functionality and needed several new ideas that as far as I know aren&#39;t present in any system or existing checker. The checker is fully compatible with TypeScript type annotations and can work without any type annotations at all.&lt;/p&gt;
&lt;h3 class=&quot;center&quot;&gt;&lt;p&gt;You can think of it as an extension to TSC, similar ideas but taken further&lt;/p&gt;
&lt;/h3&gt;
&lt;p&gt;The next few sections go into some unique features of the checker before going into the real benefit of having all this information about types.&lt;/p&gt;
&lt;h2 id=&quot;dependent-typing&quot; tabindex=&quot;-1&quot;&gt;Dependent typing&lt;/h2&gt;
&lt;p&gt;One of the key ideas with Ezno is that it attempts &amp;quot;maximum&amp;quot; knowledge of a source. This knowledge includes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Runtimes exception that could happen because of missing properties&lt;/li&gt;
&lt;li&gt;Code that will never run&lt;/li&gt;
&lt;li&gt;Expressions that could be collapsed to reduce work&lt;/li&gt;
&lt;li&gt;Mutations to data&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Because of the dynamism of JavaScript, this requires including references to constants (aka known numbers, booleans, strings, etc) in the type system.&lt;/p&gt;
&lt;p&gt;While TypeScript includes dependent types, Ezno has built on top of that doing more such as constant operator evaluation.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/00-constant-operators.png&quot; alt=&quot;Type &#39;6&#39; is not assignable to type &#39;5&#39;&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Scaling this up you can now see this working for both identifying an invalid property and detecting dead code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;key3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() { &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { someProp: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; } }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;obj[&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;key&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]().nonProp;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;five&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (five &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// do stuff&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;key3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() { &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { someProp: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; } }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;obj[&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;key&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]().nonProp;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;five&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (five &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// do stuff&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p 2=&quot;&quot; someProp:=&quot;&quot;&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/01-constant-access.png&quot; alt=&quot;Expression is always false, No property with &#39;nonProp&#39; on { someProp: 2 }&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;h3 id=&quot;objects&quot; tabindex=&quot;-1&quot;&gt;Objects&lt;/h3&gt;
&lt;p&gt;As well as identifying terms like &lt;code&gt;4&lt;/code&gt; and &lt;code&gt;&amp;quot;hello&amp;quot;&lt;/code&gt;, Ezno also treats objects and functions as constant terms:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ({} &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {}) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// dead code, two different objects&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; b) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// always true, reference to same object&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() { &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; func; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (func &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;func2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// always true 👀&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ({} &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {}) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// dead code, two different objects&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; b) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// always true, reference to same object&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() { &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; func; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (func &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;func2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// always true 👀&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/02-dependent-objects.png&quot; alt=&quot;Expression is always true, Expression is always true, Expression is always false&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;making-all-function-parameters-generic%2Fdependent&quot; tabindex=&quot;-1&quot;&gt;Making all function parameters generic/dependent&lt;/h2&gt;
&lt;p&gt;While the examples showcase great static analysis of a sequence of statements. Synthesis can be more difficult when it breaks into functions and knowing what happens across call sites. Ezno can trace the flow of data and actions on it &lt;strong&gt;by treating every parameter as what most languages refer to as &lt;em&gt;generic&lt;/em&gt;&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;addOne&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;three&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;four&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;addOne&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(four);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;addOne&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;three&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;four&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;addOne&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(four);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Here the &lt;code&gt;addOne&lt;/code&gt; function is annotated that it returns a &lt;code&gt;number&lt;/code&gt;. But instead internally in Ezno the actual result is what it synthesised that it returned. The &lt;code&gt;number&lt;/code&gt; in the return type is only used as a constraint on the type returned in body. The synthesised return type that Ezno uses in this case is &lt;code&gt;Add&amp;lt;T, 1&amp;gt;&lt;/code&gt;. In total Ezno internally views the function as: &lt;code&gt;addOne: &amp;lt;T extends number&amp;gt;(x: T): Add&amp;lt;T, 1&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;untyped-parameters&quot; tabindex=&quot;-1&quot;&gt;Untyped parameters&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Parameters that don&#39;t have a type annotation have inferred constraints based on usage in the function body&lt;/strong&gt;. The simplest is a function with no constraints:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;Hello World&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;Hello World&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;x&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/04-inferred-as-any.png&quot; alt=&quot;assertion passed with: 2, &#39;Hello World&#39;, &#39;x&#39;&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Here when the &lt;code&gt;id&lt;/code&gt; function is synthesized it infers the &lt;code&gt;a&lt;/code&gt; parameter as being generic and thus the function takes the type &lt;code&gt;&amp;lt;T extends any&amp;gt;(a: T) =&amp;gt; T&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;inferred-generic-restrictions&quot; tabindex=&quot;-1&quot;&gt;Inferred generic restrictions&lt;/h3&gt;
&lt;p&gt;In the above usage, the constraint of parameter &lt;code&gt;a&lt;/code&gt; is initialized as &lt;code&gt;any&lt;/code&gt;. Its usage in the block didn&#39;t require narrowing it down so it stayed as &lt;code&gt;any&lt;/code&gt;. Now moving on to a slightly more complex function:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;runMap&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; obj.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(func)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;runMap&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;func&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; obj.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(func)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here initially &lt;code&gt;obj&lt;/code&gt; and &lt;code&gt;func&lt;/code&gt; are generics that alias &lt;code&gt;any&lt;/code&gt;. However, usage of the &lt;code&gt;obj&lt;/code&gt; parameter has inferred for the &lt;code&gt;runMap&lt;/code&gt; to be type safe &lt;code&gt;obj&lt;/code&gt; must have a &lt;code&gt;map&lt;/code&gt; property and that &lt;code&gt;map&lt;/code&gt; property must be callable with &lt;code&gt;func&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;runMap&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;({}, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; v);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;runMap&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;({}, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; v);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is because the &lt;code&gt;.map&lt;/code&gt; synthesis changed the alias. The function is synthesized to &lt;code&gt;&amp;lt;T extends { map: (a: U) =&amp;gt; any }, U&amp;gt;(obj: T, func: U) =&amp;gt; T[&amp;quot;map&amp;quot;](U)&lt;/code&gt;. (where the return type is the call of &lt;code&gt;obj.map&lt;/code&gt; with parameter &lt;code&gt;U&lt;/code&gt;).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;runMap&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(myArray, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; v));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;runMap&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	{ &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;cb&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) { &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;cb&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) } }, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; v &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;runMap&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(myArray, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; v));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;runMap&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	{ &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;cb&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) { &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;cb&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) } }, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; v &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;It is important to note that Ezno isn&#39;t the first JavaScript type checker that has inferred generics. &lt;a href=&quot;https://hegel.js.org/&quot;&gt;Hegel&lt;/a&gt; infers generics for functions. However I when tried on the above example with its more complicated two levels of inference, Hegel could not figure it out.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The benefit here with generics is that the function can be very expressive and dynamic, but the function still &lt;strong&gt;passes off maximum information to the scope where the call occurred&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;free-variables-(hidden-parameters)-of-functions&quot; tabindex=&quot;-1&quot;&gt;Free variables (&lt;em&gt;hidden&lt;/em&gt; parameters) of functions&lt;/h3&gt;
&lt;p&gt;The usage of &lt;code&gt;this&lt;/code&gt; is a hidden parameter to functions, it is specified by the bounded structure rather than arguments at the call site. Here Ezno treats it as generic but separate from actual parameters:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getThis&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Window&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getThis&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(getThis.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;call&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getThis&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Window&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getThis&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(getThis.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;call&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Variables in parent scopes work similarly to this. Rather than being passed through the call site it instead exists in a parent of the current environment as:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	a.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;doThing&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;a.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;doThing&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; () &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;Hello world&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	a.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;doThing&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;a.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;doThing&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; () &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;Hello world&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/07-free-variables.png&quot; alt=&quot;Calling function requires &#39;a&#39; to be { doThing(): any }, found {  }&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This works using the same generic system that function parameters use. For variables without a type annotation on the variable, it reuses the inferred generic system.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The example above also shows a sneaky feature of Ezno...&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;effects%2Fevents&quot; tabindex=&quot;-1&quot;&gt;Effects/events&lt;/h2&gt;
&lt;p&gt;One of the problems of JS is that functions can be impure. Impure means it can apply side effects that are not tracked through the returned type.&lt;/p&gt;
&lt;p&gt;Ezno tracks &lt;em&gt;side effects&lt;/em&gt; that a function may perform:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { x: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getFive&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    obj.x &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(data.x);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getFive&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(data));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(data.x);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { x: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getFive&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;obj&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    obj.x &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(data.x);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getFive&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(data));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(data.x);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here this function data-wise returns a number with proof of it being equal to &lt;code&gt;5&lt;/code&gt;. But there are additional &amp;quot;effects&amp;quot; that aren&#39;t encoded into that return type. When synthesizing functions Ezno tracks mutations through a system in the context/environment called events. &lt;strong&gt;Events in a function then get associated with the function referring to the &amp;quot;effects of the function&amp;quot;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/ezno-screenshots/08-effects.png&quot; alt=&quot;assert&quot; class=&quot;invertible&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The events sequence is sort of a typed intermediate representation and is additionally used for optimisations involving used assignments and such. This has some similarities to SSA. But it is integrated into the checker and is based on types.&lt;/p&gt;
&lt;h2 id=&quot;constant-functions&quot; tabindex=&quot;-1&quot;&gt;Constant functions&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Ezno treats function uniquely with a &lt;em&gt;pointer&lt;/em&gt; to a function instead of just a &amp;quot;shape&amp;quot; (the same way constant terms and object references work).&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;We have seen some calculations on operators being calculated at compile time, but the idea carries over to many internal functions. This means it has a direct binding to the function. From this, it can be definitively known that this function is &lt;code&gt;Math.sqrt&lt;/code&gt; allowing the following to work:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;floor&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;sqrt&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;floor&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Math&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;sqrt&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This applies to more functions than just that in &lt;code&gt;Math&lt;/code&gt;. The following also applies to many other functions in the standard library. Here we see effects, &lt;code&gt;this&lt;/code&gt; treated as generic and constant functions at play:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;myObj&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	name: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;uppercase&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.name &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.name.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;toUppercase&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(myObj.name);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;myObj.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;uppercase&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;HELLO WORLD&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(x.name);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Also explicit this calling:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;otherObj&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { name: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;make me upper&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;myObj.uppercase.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;call&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(otherObj);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;MAKE ME UPPER&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(otherObj.name);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;myObj&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	name: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;uppercase&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.name &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.name.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;toUppercase&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;hello world&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(myObj.name);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;myObj.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;uppercase&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;HELLO WORLD&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(x.name);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Also explicit this calling:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;otherObj&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { name: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;make me upper&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;myObj.uppercase.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;call&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(otherObj);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;MAKE ME UPPER&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(otherObj.name);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;jsx&quot; tabindex=&quot;-1&quot;&gt;JSX&lt;/h3&gt;
&lt;p&gt;Ezno has support for JSX syntax. A key part of this implementation is that it treats different tags as different tags:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;HTMLParagraphElement&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;Paragraph tag&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;HTMLParagraphElement&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;Paragraph tag&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It also records more information about the relation of elements to interpolated data and event listeners. (Using the same system that Ezno uses to identify unique objects).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;onClick&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;HTMLParagraphElement&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(ev.currentTarget);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;Paragraph tag&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;onClick&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;assertType&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;HTMLParagraphElement&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(ev.currentTarget);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;Paragraph tag&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can think of these as being similar to objects with properties. But in this case, the children binding follow through:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;LazyImage&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;img&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{href} &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;loading&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;lazy&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;const myImage = LazyImage(myInput);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;assertType&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;(myImage.getAttribute(&amp;quot;href&amp;quot;) === myInput);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;LazyImage&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;img&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{href} &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;loading&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;lazy&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;const myImage = LazyImage(myInput);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;assertType&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;(myImage.getAttribute(&amp;quot;href&amp;quot;) === myInput);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Which leads on to the reason for adding these bindings:&lt;/p&gt;
&lt;h1 id=&quot;the-%22framework%22&quot; tabindex=&quot;-1&quot;&gt;The &amp;quot;framework&amp;quot;&lt;/h1&gt;
&lt;p&gt;One of the biggest uses of JS is with declarative user interface programming.&lt;/p&gt;
&lt;p&gt;React is one of the most popular libraries for declarative interfaces. However, its internals are computationally expensive. With Ezno one of the goals was to provide enough static analysis to work with the expressiveness of React but use the information to make it do a lot less work.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;quot;framework&amp;quot; is a temporary name for the plugin written on-top of Ezno, Ezno is not the framework. The &amp;quot;framework&amp;quot; is a plugin using logic from the parser &lt;strong&gt;and checker&lt;/strong&gt; and is entirely detachable.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;eliminating-the-need-for-a-virtual-document-object-(vdom)&quot; tabindex=&quot;-1&quot;&gt;Eliminating the need for a Virtual Document Object (VDOM)&lt;/h2&gt;
&lt;p&gt;Firstly, a definition of the VDOM (from &lt;a href=&quot;https://kaleidawave.github.io/posts/web-terminology/#vdom&quot;&gt;my web definitions post&lt;/a&gt;):&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The virtual DOM is a structure akin to the DOM. It is slimmer and has a subset of the API of the structures defined in the DOM JS spec e.g. &lt;code&gt;HTMLElement.&lt;/code&gt; VDOM is a &lt;em&gt;virtual&lt;/em&gt; representation of the document, actual DOM references the document (e.g. &lt;code&gt;.click()&lt;/code&gt; isn&#39;t on VDOM structures).&lt;/p&gt;
&lt;p&gt;It is used to add to or update the existing actual DOM/UI.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;When the application state changes it recreates the UI by rerunning functions that generate VDOM and use a the difference between the new result with a previous result to make changes/reconcile to the actual DOM/UI. This is a &lt;em&gt;declarative&lt;/em&gt; style of programming, where the UI is a &lt;em&gt;map&lt;/em&gt; from the state to UI. It is often simpler than &lt;strong&gt;manually&lt;/strong&gt; writing the &lt;em&gt;imperative&lt;/em&gt; updates to the document at every state change.&lt;/p&gt;
&lt;h3 id=&quot;the-vdom-isn&#39;t-free&quot; tabindex=&quot;-1&quot;&gt;The VDOM isn&#39;t free&lt;/h3&gt;
&lt;p&gt;Before we go into eliminating it we have to deal with the why? As well as the downsides that should occur in the alternative.&lt;/p&gt;
&lt;p&gt;Every time an update to the state happens, the runtime needs to rebuild the UI whole tree. This is necessary to find that any of the nodes have changed, but the majority of the new UI hasn&#39;t changed and you have to create and store duplicate nodes. The UI can require evaluating expensive calculations that often return the existing value.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Memoization partially solves this, parts of the tree can be wrapped and when compute them it looks for cached versions of the computation. While this solves the recreation time there is additional memory overhead to hold the cached results and hashing and lookup is not free. It is also developer overhead to realise what is static and independent. Extra explicit-ness in the syntax (unless a auto memoising compiler was added), just overall more complicated.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Additionally, to do this handling with the VDOM the library has to be shipped with a reconciler on top of the state handler and the diffing algorithm, all leading to &lt;strong&gt;larger JS payloads&lt;/strong&gt;. There is also the process of starting up the client after SSR. Unless event listener delegation is used ahead of time, when adding event listeners to existing markup VDOM it requires a representation of the whole tree to find event listeners. And even if the event listeners are delegated, a VDOM framework requires creating the existing UI tree to perform updates on an existing server-rendered tree, which requires loading the whole state.&lt;/p&gt;
&lt;h2 id=&quot;vdom-without-the-vdom&quot; tabindex=&quot;-1&quot;&gt;VDOM without the VDOM&lt;/h2&gt;
&lt;p&gt;One of the questions for this project was &#39;What analysis do you need to do to use JSX and the full range of JS expressions that React works with, without running into the complexities and execution expensiveness of a VDOM?&#39;.&lt;/p&gt;
&lt;p&gt;Because of the tracking of &lt;em&gt;poly-types&lt;/em&gt; in Ezno&#39;s checker, the values passed around &lt;code&gt;useState&lt;/code&gt; can be reasoned with. For example this is what is tracked from the left and right values from a &lt;code&gt;useState&lt;/code&gt; call.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;setValue&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;useState&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//                value : any (via dynamic constraint)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//              / [0]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// useState(&amp;quot;&amp;quot;) &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//              &#92; [1]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//                setValue : (any) =&amp;gt; any&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;setValue&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;useState&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//                value : any (via dynamic constraint)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//              / [0]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// useState(&amp;quot;&amp;quot;) &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//              &#92; [1]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//                setValue : (any) =&amp;gt; any&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Because of this, we have three unique types created from this statement that can be tracked.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;onChange&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;setState&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(ev.target.value)}&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;{value}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;input&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;onChange&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;setState&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(ev.target.value)}&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;{value}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Building a compiler to generate imperative calls &lt;em&gt;is then very simple&lt;/em&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Find calls where a function calls the state a function that modifies state (for example &lt;code&gt;useState()[1]&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Lookup element points (attributes, children, etc) that are of a type where the base &lt;code&gt;useState&lt;/code&gt; is the same &lt;code&gt;useState()[0]&lt;/code&gt; (type synthesis stores reverse references on objects)&lt;/li&gt;
&lt;li&gt;Replace &lt;code&gt;setState&lt;/code&gt; call with direct DOM updates that affect the element points&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These updates are relative to the elements in the DOM as these relationships are found during the type synthesis. Therefore the above would generate something similar to:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;input.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;change&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, ({ &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;target&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	target.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;nextElementSibling&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;().innerText &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; target.value;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;});&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;input.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;change&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, ({ &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;target&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	target.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;nextElementSibling&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;().innerText &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; target.value;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;});&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here the type information enables generation of this direct update instead of relying on a VDOM at runtime to find this change.&lt;/p&gt;
&lt;h3 id=&quot;state-objects&quot; tabindex=&quot;-1&quot;&gt;State objects&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;useProxy&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;({ count: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;updateCount&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	value.count&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;{count}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;useProxy&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;({ count: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;updateCount&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	value.count&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;{count}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This sort of thing works in &lt;a href=&quot;https://github.com/pmndrs/valtio&quot;&gt;valtio&lt;/a&gt; and is the previous implementation in my old framework &lt;a href=&quot;https://kaleidawave.github.io/posts/prism-one-point-five/&quot;&gt;Prism&lt;/a&gt;. This is possible using &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy&quot;&gt;Proxies&lt;/a&gt; at runtime, but suffer from many complications at runtime.&lt;/p&gt;
&lt;p&gt;Because of effect tracking in Ezno, it becomes fairly straightforward to find state mutations across functions so these updates can be found and inlined similar to the above. The uniqueness of functions here enables special handling of &lt;code&gt;.map&lt;/code&gt; and &lt;code&gt;.push&lt;/code&gt; as they are known to be array methods after the type synthesis.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;useProxy&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;({ items: [] });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;onClick&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{() &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value.items.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;())}&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	{value.items.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;{item}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;)}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;useProxy&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;({ items: [] });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;onClick&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{() &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value.items.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;())}&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	{value.items.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;{item}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;)}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;From this, the logic can work out that calling &lt;code&gt;.push&lt;/code&gt; appends a new element to the &lt;code&gt;ul&lt;/code&gt; element. Therefore it can skip over needing keys and finding list differences in this scenario and generate a simple &lt;code&gt;.appendChild&lt;/code&gt; call.&lt;/p&gt;
&lt;h2 id=&quot;universality%2C-adding-event-listeners-and-hydration&quot; tabindex=&quot;-1&quot;&gt;Universality, adding event listeners and hydration&lt;/h2&gt;
&lt;p&gt;Most frameworks enable some sort of &lt;a href=&quot;https://kaleidawave.github.io/posts/web-terminology/#ssr&quot;&gt;server-side rendering (often abbreviated to SSR)&lt;/a&gt;. SSR is the functionality in the framework to generate a HTML string representation of the same UI under a state identically to the result on the browser. It is also used in static site generation where the build tool runs all the requests at build time and saves the results to some sort of static output.&lt;/p&gt;
&lt;p&gt;As Ezno knows about bindings and the type interpolated, that information can be used inside the compiler to hydrate the state from the rendered HTML.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;setA&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;useState&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;onClick&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{() &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;setA&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)}&amp;gt;{a}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;setA&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;useState&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;onClick&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{() &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;setA&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)}&amp;gt;{a}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;button.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;click&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, ({ &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;target&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	target.innerText &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;parseInt&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(target.innerHTMl) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;//                 ^^^^^^^^^^^^^^^^^^^^^^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Here is the reverse expression. Again it knows about types so can invert the implicit cast of a integer to a string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;});&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;button.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;click&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, ({ &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;target&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	target.innerText &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;parseInt&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(target.innerHTMl) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;//                 ^^^^^^^^^^^^^^^^^^^^^^^^^^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Here is the reverse expression. Again it knows about types so can invert the implicit cast of a integer to a string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;});&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For upgrading existing HTML, rather than each element registering an event listener (which can result in hundreds of &lt;code&gt;addEventListener&lt;/code&gt; calls) it instead can a single one at the top level. The output of the framework &lt;em&gt;is still a work in progress&lt;/em&gt; but with the bijective property map, the position of elements works without the notion of components.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;createRoot&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(document.body).&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;render&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(() &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;onClick&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{() &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;clicked&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)}&amp;gt;Log click&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;onClick&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; () &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;/do-thing&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) }}&amp;gt;Make request&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&amp;gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;createRoot&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(document.body).&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;render&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(() &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;onClick&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{() &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;clicked&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)}&amp;gt;Log click&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;onClick&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; () &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;/do-thing&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) }}&amp;gt;Make request&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&amp;gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;possible compiled output:&lt;/em&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;document.body.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;click&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; ({ &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;target&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; }) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; target.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getAttribute&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;data-click&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (id &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		console.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;clicked&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	} &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (id &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;/do-thing&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;});&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;document.body.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;click&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; ({ &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;target&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; }) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; target.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getAttribute&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;data-click&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (id &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;0&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		console.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;log&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;clicked&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	} &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (id &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;===&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;1&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;		&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;/do-thing&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;});&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;other-ideas&quot; tabindex=&quot;-1&quot;&gt;Other ideas&lt;/h2&gt;
&lt;p&gt;Some other ideas that type information can enable:&lt;/p&gt;
&lt;h3 id=&quot;server-side-rendering-out-of-the-javascript-runtime&quot; tabindex=&quot;-1&quot;&gt;Server-side rendering out of the JavaScript runtime&lt;/h3&gt;
&lt;p&gt;One of the problems with JavaScript frontend server rendering implementations is that SSR/&amp;quot;string builders&amp;quot; run on JavaScript which means they are locked into a server runtime like Node or Deno. This is perfectly fine for most things but I think this is generally quite a heavy restriction, which prevents using a lot of cool backend technologies written in other languages like Rust, Python etc. Some tools have embedded a JavaScript runtime into the application (such as &lt;a href=&quot;https://github.com/denoland/rusty_v8&quot;&gt;rusty_v8&lt;/a&gt;). However, joining these two systems together &lt;em&gt;can&lt;/em&gt; lose type safety bridge and data often has to be copied into the runtime which seems to void the performance improvements.&lt;/p&gt;
&lt;p&gt;With type information, it could allow Ezno to generate some format that is tightly integrated with the server language. This is quite simple to do for string elements and Ezno knows the shape of data and the pointer to every function it could easily transpile some of this stuff. However, it is still up in the air how this would work if the server has to do something more complicated mutating data and I don&#39;t have a clear idea of what the format would be that could be used across languages would look like.&lt;/p&gt;
&lt;h3 id=&quot;auto-progressive-enhancement&quot; tabindex=&quot;-1&quot;&gt;Auto progressive enhancement&lt;/h3&gt;
&lt;p&gt;As Ezno knows at compile time what functions have been bound to certain event listeners plus the internal effects it knows to extract runtime state mutations to the server to add a backup to client-side interactions if JavaScript fails to load.&lt;/p&gt;
&lt;h2 id=&quot;plugins-and-extensibility&quot; tabindex=&quot;-1&quot;&gt;Plugins and extensibility&lt;/h2&gt;
&lt;p&gt;Ezno is written in Rust and has several places/hooks for adding additional functionality:&lt;/p&gt;
&lt;h3 id=&quot;exterior-type-safety&quot; tabindex=&quot;-1&quot;&gt;Exterior type safety&lt;/h3&gt;
&lt;p&gt;Because &lt;a href=&quot;https://kaleidawave.github.io/posts/introducing-ezno/#objects&quot;&gt;Ezno treats functions as unique&lt;/a&gt; it allows for special handling of functions via Ezno&#39;s plugin system.&lt;/p&gt;
&lt;p&gt;For example, the &lt;code&gt;fetch&lt;/code&gt; function could be overridden and known strings could return a more precise type based on knowledge of what an endpoint returns.&lt;/p&gt;
&lt;h3 id=&quot;build-tool-front-ends&quot; tabindex=&quot;-1&quot;&gt;Build tool front-ends&lt;/h3&gt;
&lt;p&gt;Aside from the CLI, there is a language server plugin (LSP) so you can use it in an editor. For those who don&#39;t like the command line build step, there is a half-working Nodejs runner, this means you can integrate the build step into the runner compressing running the source into a single command. For the web, there is a WASM service worker runner that shouldn&#39;t need to touch the filesystem during development.&lt;/p&gt;
&lt;h1 id=&quot;complexity-%26-wrapping-up-the-features&quot; tabindex=&quot;-1&quot;&gt;Complexity &amp;amp; wrapping up the features&lt;/h1&gt;
&lt;p&gt;Enough with the features here is a roundup and some philosophy of the project&lt;/p&gt;
&lt;h2 id=&quot;types&quot; tabindex=&quot;-1&quot;&gt;Types&lt;/h2&gt;
&lt;p&gt;Types are an integral part of JavaScript with features like &lt;code&gt;instanceof&lt;/code&gt; and &lt;code&gt;typeof&lt;/code&gt;. TSC, Flow, Hegel, Ezno and other checkers reason with this runtime behavior ahead of time, which can help find errors before they find themselves. However, unlike JavaScript this ahead of time behavior isn&#39;t specified and so each checker has different approaches to what and how it should emit &lt;em&gt;type errors&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id=&quot;places-where-ezno-diverges-from-typescript&quot; tabindex=&quot;-1&quot;&gt;Places where Ezno diverges from TypeScript&lt;/h3&gt;
&lt;p&gt;Given TSC has the largest share in the JavaScript type checking ecosystem, I think it is really beneficial for Ezno to be usable in projects currently using TSC. Many of the ideas from TSC have been included in Ezno, with Ezno going the extra mile in many cases to be more sound so that it can use type-information for build time optimisations.&lt;/p&gt;
&lt;p&gt;One of the big things is that Type annotations in source code are treated as restrictions under Ezno and so are not strictly necessary. Ezno prefers to use the JavaScript as the source of truth. From the previous section on events and generic calls, the information needed to generate more accurate results is more complex (and verbose) than simple annotations allow, thus why it is prefered to generate this from the JS code rather than require nnoations.&lt;/p&gt;
&lt;p&gt;Also, TypeScript has allows breaking out the type system by the &lt;code&gt;any&lt;/code&gt; type to be cast as a specific type (such as &lt;code&gt;string&lt;/code&gt; in the following example).&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Passes under TSC&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;slice&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Passes under TSC&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;any&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;	&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;slice&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Implementing &lt;code&gt;any&lt;/code&gt; this way makes TypeScript easier to adopt and allows things to compile in weird environments. However for Ezno to do its optimisations this magic &lt;code&gt;any&lt;/code&gt; type that has the property of all types without narrowing doesn&#39;t quite work.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Don&#39;t take Ezno&#39;s features as a knock on TypeScript, TypeScript is great&lt;/strong&gt;. Ezno started as a pet project to reimplement the features of TSC in Rust. But as things started to go well after adding more and more TSC features, it was apparent that optimisations such as the hydration and the reactive systems weren&#39;t going to be possible directly following its path. It isn&#39;t possible to detect what can happen to the state when called through a term that represents &lt;code&gt;any&lt;/code&gt;. TypeScript &lt;em&gt;holes&lt;/em&gt; aren&#39;t particularly critical if you just want code completions and some basic errors to be caught. They allow the more complex parts to not be blocked by compiler errors. &lt;strong&gt;But for doing optimizations a single unknown result can make it impossible&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The hope is with diverging and trying to extend TSC will help in staying up to date with newer TypeScript features (as it will be ahead, rather than behind).&lt;/p&gt;
&lt;p&gt;Currently Ezno isn&#39;t a feature-complete type checker. There are still a lot of things to still work on. So far the first section goes over the analysis of completely static code. The next step is to apply these ideas to more dynamic structures. There are also some ideas not mentioned here to prevent this post from being too long 👀.&lt;/p&gt;
&lt;h2 id=&quot;frameworks&quot; tabindex=&quot;-1&quot;&gt;Frameworks&lt;/h2&gt;
&lt;p&gt;The output of the framework is still a work in progress. There are still a few things to add to the type checker that are necessary to get &amp;quot;the framework&amp;quot; plugin to work in edge cases. Thus no benchmarks or definite output in this post. Most benchmarks show hand-written JavaScript code to be the most efficient so the idea is to take the syntax and information about it to squeeze it into the closest of the hand-written forms. The performance gains from all these optimisations are probably unnoticeable. This is an exercise in attempting to get to the least amount of code to run to make a page interactive.&lt;/p&gt;
&lt;p&gt;Some frameworks abstract through libraries and the structure of functions. Some compiler-based frameworks abstract through syntax. Ezno&#39;s framework is unique it is based on data and the semantics of the program above what is visible from the syntax.&lt;/p&gt;
&lt;h2 id=&quot;ezno-today&quot; tabindex=&quot;-1&quot;&gt;Ezno today&lt;/h2&gt;
&lt;p&gt;I think it is fun short and quirky and most importantly, not taken on package registries.&lt;/p&gt;
&lt;p&gt;I want to keep things moving but slowly. I think incomplete projects are good as they have space to add additional features and improve. Some projects I see which seem closer to their goal have less space to improve. I think some tools are built too quickly and I don&#39;t want Ezno to fall into that category.&lt;/p&gt;
&lt;p&gt;&lt;s&gt;No demo binary out yet, need to finish off some things on more advanced events to get some of the cooler demos to work. Hoping for something demonstrable before the end of this year 🤞&lt;/s&gt;&lt;/p&gt;
&lt;h3 id=&quot;ezno-and-its-checker-are-now-public-as-of-2023&quot; tabindex=&quot;-1&quot;&gt;&lt;a href=&quot;https://github.com/kaleidawave/ezno&quot;&gt;Ezno and its checker are now public as of 2023&lt;/a&gt;&lt;/h3&gt;
</content>
  </entry>
  <entry>
    <title>Definitions of web terminology</title>
    <link href="https://kaleidawave.github.io/posts/web-terminology/"/>
    <updated>2022-03-31T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/web-terminology/</id>
    <summary>A bunch of definitions for terms thrown around in web development</summary>
    <content xml:lang="en" type="html">&lt;h3 id=&quot;rendering&quot; tabindex=&quot;-1&quot;&gt;Rendering&lt;/h3&gt;
&lt;p&gt;The act of turning data or state into some representation of HTML.&lt;/p&gt;
&lt;h3 id=&quot;ssr&quot; tabindex=&quot;-1&quot;&gt;Server-side rendering (SSR)&lt;/h3&gt;
&lt;p&gt;A process that produces a string/text buffer of the HTML format by a server (a machine that is not the client). Note that this can be stored in buffers on a server as a cache or can be saved to &lt;em&gt;files&lt;/em&gt; as static site generation.&lt;/p&gt;
&lt;h3 id=&quot;csr&quot; tabindex=&quot;-1&quot;&gt;Client-side rendering (CSR)&lt;/h3&gt;
&lt;p&gt;A string/text representation of HTML or &lt;code&gt;HTMLElement&lt;/code&gt;s that is created locally on the client (the same CPU, this includes web workers and service workers).&lt;/p&gt;
&lt;h3 id=&quot;hydration&quot; tabindex=&quot;-1&quot;&gt;Hydration&lt;/h3&gt;
&lt;p&gt;Hydration is the code that &lt;a href=&quot;https://stackoverflow.com/questions/6991135/what-does-it-mean-to-hydrate-an-object&quot;&gt;associates the state of an item with an existing object&lt;/a&gt;. On the web, this refers to creating state in JS that matches &lt;a href=&quot;https://kaleidawave.github.io/posts/web-terminology/#ssr&quot;&gt;server-side rendered&lt;/a&gt; DOM, which then enables client-side interactivity. It has origins in &lt;a href=&quot;https://www.snaplogic.com/glossary/data-hydration&quot;&gt;database&lt;/a&gt; and originates from the &lt;a href=&quot;https://hydrate.sourceforge.net/&quot;&gt;hydrate project from 2006&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;partial-hydration&quot; tabindex=&quot;-1&quot;&gt;Partial hydration/Island architecture&lt;/h3&gt;
&lt;p&gt;Partial hydration (for a full page) is only hydrating certain dynamic elements (not &lt;a href=&quot;https://kaleidawave.github.io/posts/web-terminology/#static-trees&quot;&gt;static trees&lt;/a&gt;). The islands refer to the dynamic trees.&lt;/p&gt;
&lt;p&gt;Partial hydration is a form of &lt;a href=&quot;https://kaleidawave.github.io/posts/web-terminology/#dead-code-elimination&quot;&gt;dead code elimination&lt;/a&gt;, where the code being removed is anything to do with static UI. This includes static components render methods and any dependencies those render methods pull in. If the state is also serialized as a JSON blob then partial hydration can remove data used by static trees.&lt;/p&gt;
&lt;p&gt;Partial hydration is an architecture, not a feature. Partial hydration/Island architecture is unrelated to &lt;a href=&quot;https://kaleidawave.github.io/posts/web-terminology/#progressive-enhancement&quot;&gt;progressive enhancement&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;progressive-hydration&quot; tabindex=&quot;-1&quot;&gt;Progressive hydration/Lazy hydration&lt;/h3&gt;
&lt;p&gt;Doing the process of hydration on interaction with a component or some other time after the page load.&lt;/p&gt;
&lt;h3 id=&quot;progressive-enhancement&quot; tabindex=&quot;-1&quot;&gt;Progressive enhancement (PE)&lt;/h3&gt;
&lt;p&gt;The act of server rendering markup that has functionality using HTML features such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Forms with endpoints&lt;/li&gt;
&lt;li&gt;Anchor tags with href&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The above features are available without JS running on the client. A server should be ready to receive the browser&#39;s requests and do stuff.&lt;/p&gt;
&lt;p&gt;Progressive enhancement can be implemented in any framework that supports server-side rendering. Although some frameworks have helpers for making this easier or the cow path. Additionally, the &lt;a href=&quot;https://kaleidawave.github.io/posts/web-terminology/#hydration&quot;&gt;hydration&lt;/a&gt; step can then add event listeners to override the default browser functionality. &lt;em&gt;progressive enhancement is not &lt;a href=&quot;https://kaleidawave.github.io/posts/web-terminology/#partial-hydration&quot;&gt;partial hydration&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Note that not every interaction can be implemented using the HTML features (e.g. mouse drawing on a canvas) so JS is required in many scenarios and often doing it in JS has a better experience. Forms and anchor tags both do full page reloads which can disrupt the state present on the client (e.g. other input contents, background audio).&lt;/p&gt;
&lt;p&gt;But doing PE is better than not doing PE. The site should be as functional as it can be because JS (the hydration) may have not run yet, at all or may have failed.&lt;/p&gt;
&lt;h3 id=&quot;design-system&quot; tabindex=&quot;-1&quot;&gt;Design system&lt;/h3&gt;
&lt;p&gt;A collection of colour themes, component designs, layouts, and assets encompassing brand image and packaged up to be easily reusable throughout the site.&lt;/p&gt;
&lt;h3 id=&quot;hmr&quot; tabindex=&quot;-1&quot;&gt;Hot module reloading/swapping&lt;/h3&gt;
&lt;p&gt;When changes happen during development it patches the changed functions rather than reloading the whole content and state.&lt;/p&gt;
&lt;h3 id=&quot;dynamic-rendering&quot; tabindex=&quot;-1&quot;&gt;Dynamic rendering&lt;/h3&gt;
&lt;p&gt;The server renders pages with data on demand.&lt;/p&gt;
&lt;h3 id=&quot;html-frames&quot; tabindex=&quot;-1&quot;&gt;HTML Frames&lt;/h3&gt;
&lt;p&gt;Sections of which content is purely server-side rendered. Note that server components may or may not be HTML frames if they don&#39;t serve HTML strings.&lt;/p&gt;
&lt;h3 id=&quot;ssg&quot; tabindex=&quot;-1&quot;&gt;Static site generation (SSG)&lt;/h3&gt;
&lt;p&gt;Generation of static HTML through server-side rendering (or some bad methods that do client-side rendering and then capture the result on a headless browser). Normally done at build time. Note that SSGs can have dynamism through client-side rendering. If a tool has server-side rendering then that mechanism can be used to store the HTML content in a file to implement SSG.&lt;/p&gt;
&lt;h3 id=&quot;isg&quot; tabindex=&quot;-1&quot;&gt;Incremental static generation (ISG)&lt;/h3&gt;
&lt;p&gt;Similar to a static site generation. Where a static site generates on build/deploy. Incremental static generation is linked to a timed interval or a hook on the change of a data source. The hook fires an event that generates new pages to reflect the new data.&lt;/p&gt;
&lt;h3 id=&quot;tti&quot; tabindex=&quot;-1&quot;&gt;Time to interactive (TTI)&lt;/h3&gt;
&lt;p&gt;The time to it takes to add event listeners with most of the functionality &lt;strong&gt;ready&lt;/strong&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Event handlers are registered for the most visible page elements&lt;/li&gt;
&lt;li&gt;The page responds to user interactions within 50 milliseconds&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;fcp&quot; tabindex=&quot;-1&quot;&gt;First contentful paint (FCP)&lt;/h3&gt;
&lt;p&gt;The time to display content from when the page starts loading (e.g. server initially responds, so this does not include the time to establish a connection). If SSR this is the time it takes to produce the HTML string and if doing purely client-side rendering then the time it takes for the JS to start running and produce the elements. This also includes initial layout working and image rendering.&lt;/p&gt;
&lt;h3 id=&quot;ttfb&quot; tabindex=&quot;-1&quot;&gt;Time to first byte (TTFB)&lt;/h3&gt;
&lt;p&gt;The time it takes for the server to initially respond. If streaming, this is the time for the first chunk. If not (aka buffering) this is the time for the content to be prepared and sent (aka a full SSR). Normally a measure of the hosting server rather.&lt;/p&gt;
&lt;h3 id=&quot;zero-js&quot; tabindex=&quot;-1&quot;&gt;No-JS/zero JS&lt;/h3&gt;
&lt;p&gt;Something with no JS running &lt;strong&gt;ever&lt;/strong&gt;. This includes &lt;a href=&quot;https://kaleidawave.github.io/posts/web-terminology/#3rd-party-scripts&quot;&gt;3rd party scripts&lt;/a&gt;. Again most pages require some form of JS, something that runs no JS is not necessarily better.&lt;/p&gt;
&lt;h3 id=&quot;sprinkles&quot; tabindex=&quot;-1&quot;&gt;Sprinkles&lt;/h3&gt;
&lt;p&gt;Using JS to add interactivity to certain parts of a server-rendered UI in small amounts. (This is not &lt;a href=&quot;https://kaleidawave.github.io/posts/web-terminology/#progressive-enhancement&quot;&gt;progressive enhancement&lt;/a&gt; as it doesn&#39;t require implementing server functionality)&lt;/p&gt;
&lt;h3 id=&quot;3rd-party-scripts&quot; tabindex=&quot;-1&quot;&gt;3rd party scripts&lt;/h3&gt;
&lt;p&gt;A script that is written &lt;em&gt;out of house&lt;/em&gt;. Examples include Google Analytics, Google Tag Manager, etc&lt;/p&gt;
&lt;h3 id=&quot;static-trees&quot; tabindex=&quot;-1&quot;&gt;Static trees&lt;/h3&gt;
&lt;p&gt;A tree that does not change/depend on variable data&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;static_tree&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;Hello&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;still_static&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;{&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;constant variable&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;not_static&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;{&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;static_tree&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;Hello&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;still_static&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;{&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;constant variable&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;not_static&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;{&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;not_static&lt;/code&gt; is dependent on a variable result and thus is a &lt;strong&gt;dynamic tree&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;re-render&quot; tabindex=&quot;-1&quot;&gt;Re-render&lt;/h3&gt;
&lt;p&gt;For VDOM or systems that need to recalculate trees after the result of an action. This term is given to the calculations for recomputing UI. Later the result of the re-render requires diffing to efficiently update the new UI.&lt;/p&gt;
&lt;h3 id=&quot;fine-grained-reactivity&quot; tabindex=&quot;-1&quot;&gt;Fine-grained reactivity&lt;/h3&gt;
&lt;p&gt;Reactivity in which knows about parts of the states and only does work in those areas.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;{title.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;toUppercase&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;{content}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;{title.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;toUppercase&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;{content}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;E.g. changing &lt;code&gt;content&lt;/code&gt; should not result in calculating &lt;code&gt;title.toUppercase()&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;This is to do with partial updates to the state. Something that skips static trees is not really fine-grained reactivity.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Note that fine-grained reactivity may include re-rendering sections that are dynamic under the state.&lt;/p&gt;
&lt;h3 id=&quot;server-component&quot; tabindex=&quot;-1&quot;&gt;Server component&lt;/h3&gt;
&lt;p&gt;Any component where its content is produced on the server either in HTML or an intermediate format.&lt;/p&gt;
&lt;h3 id=&quot;memoization&quot; tabindex=&quot;-1&quot;&gt;Memoization&lt;/h3&gt;
&lt;p&gt;The process of caching function return values against the inputs. If a function takes a long to compute the result and is rerun a lot then this can speed up getting the result as it takes a map lookup rather than a re-computation.&lt;/p&gt;
&lt;p&gt;An auto-memoization compiler can wrap function calls with a cache lookup and storage.&lt;/p&gt;
&lt;p&gt;Note that this is an optimization at call sites, this can be avoided via rearranging when data is calculated and passed through.&lt;/p&gt;
&lt;p&gt;This technique incurs memory overhead due to the need to store all results of the function. And for many cases a map lookup can be slower than just doing the operation.&lt;/p&gt;
&lt;h3 id=&quot;actions&quot; tabindex=&quot;-1&quot;&gt;Actions&lt;/h3&gt;
&lt;p&gt;Something that mutates a specific part of the state.&lt;/p&gt;
&lt;h3 id=&quot;effects&quot; tabindex=&quot;-1&quot;&gt;Effects&lt;/h3&gt;
&lt;p&gt;Results of those actions. e.g. changing a value may require updating the content element in the templating interpolation.&lt;/p&gt;
&lt;h3 id=&quot;diffing&quot; tabindex=&quot;-1&quot;&gt;Diffing&lt;/h3&gt;
&lt;p&gt;Finding differences between an existing representation and a new representation.&lt;/p&gt;
&lt;p&gt;Diffing techniques do not always apply to VDOM. Diffing can be done on structures that do not look like DOM. Such as a flat list.&lt;/p&gt;
&lt;p&gt;Produces a diff/difference that can be used for reconciliation.&lt;/p&gt;
&lt;h3 id=&quot;conciliation&quot; tabindex=&quot;-1&quot;&gt;Conciliation/reconciliation&lt;/h3&gt;
&lt;p&gt;This applies to virtual DOM and other representations e.g. lists.&lt;/p&gt;
&lt;p&gt;It is the act of taking the results of the diff and updating the UI. The diff should describe the minimum amount of work to update the UI).&lt;/p&gt;
&lt;h3 id=&quot;css-in-js&quot; tabindex=&quot;-1&quot;&gt;CSS in JS&lt;/h3&gt;
&lt;p&gt;Some notion of writing styles in JS. Normally via object literals that look like CSS syntax. Unsure whether this covers &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; JSX tags and template literals...&lt;/p&gt;
&lt;h3 id=&quot;frontend&quot; tabindex=&quot;-1&quot;&gt;Frontend&lt;/h3&gt;
&lt;p&gt;Frontend is what is interpreted by the client. Public and visible to all. Includes communication with backend (but not implementation).&lt;/p&gt;
&lt;h3 id=&quot;backend&quot; tabindex=&quot;-1&quot;&gt;Backend&lt;/h3&gt;
&lt;p&gt;Something that does not run on the client. Owned by an operator, distributes data and effects across clients. The backend includes the serving of content and HTTP responses etc&lt;/p&gt;
&lt;h3 id=&quot;full-stack&quot; tabindex=&quot;-1&quot;&gt;Full stack&lt;/h3&gt;
&lt;p&gt;The combination of frontend and backend. Full stack knowledge is knowing both sides of the network. A full-stack framework has features spread across frontend and backend&lt;/p&gt;
&lt;h3 id=&quot;spa&quot; tabindex=&quot;-1&quot;&gt;Single page application (SPA)&lt;/h3&gt;
&lt;p&gt;A page that does not use the browser&#39;s built-in navigation to do page transitions. &lt;strong&gt;It does not mean that there is only one page, only that the browser internally thinks it is on the same page&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Can be faster as only have to update regions between pages, and can retain state between navigations. Implementations should be using the history API so that the browser&#39;s back buttons still function. New page contents can be generated using client-side rendering or by retrieving and injecting server-rendered content.&lt;/p&gt;
&lt;p&gt;A SPA can be server rendered initially and this architecture makes it simple to build a &lt;a href=&quot;https://kaleidawave.github.io/posts/web-terminology/#pwa&quot;&gt;PWA&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;mpa&quot; tabindex=&quot;-1&quot;&gt;Multi page application (MPA)&lt;/h3&gt;
&lt;p&gt;A page of which links cause inbuilt browser navigation. Pages are exclusively server-rendered (but parts of them can be changed via the client).&lt;/p&gt;
&lt;h3 id=&quot;pwa&quot; tabindex=&quot;-1&quot;&gt;Progressive web application (PWA)&lt;/h3&gt;
&lt;p&gt;This encompasses a lot, but the main points are that it is built using web technologies but can do the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Installable (act like a native app)&lt;/li&gt;
&lt;li&gt;Work offline (functionality does not require talking to a server &lt;em&gt;all&lt;/em&gt; the time, &lt;em&gt;some&lt;/em&gt; content is stored on the device)&lt;/li&gt;
&lt;li&gt;Doesn&#39;t have to but uses several native APIs: camera, clipboard, background fetch, push notifications&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;static&quot; tabindex=&quot;-1&quot;&gt;Static&lt;/h3&gt;
&lt;p&gt;Cannot change.&lt;/p&gt;
&lt;h3 id=&quot;dynamic&quot; tabindex=&quot;-1&quot;&gt;Dynamic&lt;/h3&gt;
&lt;p&gt;Can change.&lt;/p&gt;
&lt;h3 id=&quot;dom&quot; tabindex=&quot;-1&quot;&gt;DOM (Document object model)&lt;/h3&gt;
&lt;p&gt;The API for HTML elements. Every HTML element has some attributes and some children either being more elements, text, or comments. DOM elements can also interact with methods like &lt;code&gt;.click()&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&quot;shadow-dom&quot; tabindex=&quot;-1&quot;&gt;Shadow DOM&lt;/h3&gt;
&lt;p&gt;A special form of DOM that is encapsulated inside the element. The internals of shadow dom are isolated from the whole DOM so that outside JS cannot reference and CSS cannot affect. CSS defined internally is scoped to the internal tree.&lt;/p&gt;
&lt;h3 id=&quot;vdom&quot; tabindex=&quot;-1&quot;&gt;Virtual DOM/VDOM&lt;/h3&gt;
&lt;p&gt;The virtual DOM is a structure akin to the DOM. It is slimmer and has a subset of the API of the structures defined in the DOM JS spec e.g. &lt;code&gt;HTMLElement.&lt;/code&gt; VDOM is a &lt;em&gt;virtual&lt;/em&gt; representation of the document, actual DOM references the document (e.g. &lt;code&gt;.click()&lt;/code&gt; isn&#39;t on VDOM structures).&lt;/p&gt;
&lt;p&gt;It is used to add to or update the existing actual DOM/UI.&lt;/p&gt;
&lt;h3 id=&quot;universal-javascript&quot; tabindex=&quot;-1&quot;&gt;Universal JavaScript/Universal rendering&lt;/h3&gt;
&lt;p&gt;Running JavaScript produced that is derived or is the same source on both the client AND the server.&lt;/p&gt;
&lt;h3 id=&quot;isomorphic-javascript&quot; tabindex=&quot;-1&quot;&gt;Isomorphic JavaScript&lt;/h3&gt;
&lt;p&gt;Same meaning as &lt;a href=&quot;https://kaleidawave.github.io/posts/web-terminology/#universal-javascript&quot;&gt;universal JavaScript&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Use of this should be discouraged as the (proper) definition of &lt;em&gt;isomorphic&lt;/em&gt; in category theory doesn&#39;t make sense here.&lt;/p&gt;
&lt;h3 id=&quot;meta-framework&quot; tabindex=&quot;-1&quot;&gt;Meta framework&lt;/h3&gt;
&lt;p&gt;A framework that is built upon one or more existing frameworks and wraps functionality. For example, nextjs that extends React.&lt;/p&gt;
&lt;h3 id=&quot;templating-language&quot; tabindex=&quot;-1&quot;&gt;Templating language&lt;/h3&gt;
&lt;p&gt;A language that can describe how to build some form of markup.&lt;/p&gt;
&lt;h3 id=&quot;imperative-templating&quot; tabindex=&quot;-1&quot;&gt;Imperative templating&lt;/h3&gt;
&lt;p&gt;A template language that has imperative notions of a declarative source.&lt;/p&gt;
&lt;h3 id=&quot;streaming&quot; tabindex=&quot;-1&quot;&gt;Streaming&lt;/h3&gt;
&lt;p&gt;Streaming is incremental sending parts enabling work to start happening without the whole of the resource being present. e.g a streaming renderer can start returning results before the whole thing has been rendered. Streaming hydration can start hydrating nodes before all the nodes are on the client.&lt;/p&gt;
&lt;h3 id=&quot;static-analysis&quot; tabindex=&quot;-1&quot;&gt;Static analysis&lt;/h3&gt;
&lt;p&gt;Something that is statically analyzable is something of which behaviour can be worked out ahead of time. It should be noted that some things that are deemed not to be statically analyzable can be made statically analyzable by introducing constraints on what can be written. It should also be used with caution as some things named under statically analyzable are but whose implementation is incredibly complex to build.&lt;/p&gt;
&lt;h3 id=&quot;markup&quot; tabindex=&quot;-1&quot;&gt;Markup&lt;/h3&gt;
&lt;p&gt;Some kind of language that is centered on content first. Markdown, HTML, and YML are based on content.&lt;/p&gt;
&lt;h3 id=&quot;compiler&quot; tabindex=&quot;-1&quot;&gt;Compiler&lt;/h3&gt;
&lt;p&gt;A program that:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Parses input into abstract syntax trees, concrete syntax trees, or some other source-based IR&lt;/li&gt;
&lt;li&gt;Transforms IR&lt;/li&gt;
&lt;li&gt;Returns some evaluatable result, or a collection of errors found&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;quot;compiling&amp;quot; is a compiler at work.&lt;/p&gt;
&lt;h3 id=&quot;transpiler&quot; tabindex=&quot;-1&quot;&gt;Transpiler&lt;/h3&gt;
&lt;p&gt;Similar to a compiler it is a source-to-source compiler. Source to source meaning the output is in the same format as the input. A transpiler is a subset of compilers.&lt;/p&gt;
&lt;p&gt;&amp;quot;transpiling&amp;quot; is a transpiler at work.&lt;/p&gt;
&lt;h3 id=&quot;ir&quot; tabindex=&quot;-1&quot;&gt;Intermediate representation (IR)&lt;/h3&gt;
&lt;p&gt;A more abstract representation of the source, may not be reversible to the original source. e.g. operation canonicalization.&lt;/p&gt;
&lt;h3 id=&quot;serverless&quot; tabindex=&quot;-1&quot;&gt;Serverless&lt;/h3&gt;
&lt;p&gt;Non-centralized computation. Similar to a pure function (without side effects) these should be small map-like functions.&lt;/p&gt;
&lt;p&gt;Note this is still run on serverless just that it abstracts away a lot of the behaviours of centralized server computations.&lt;/p&gt;
&lt;h3 id=&quot;api&quot; tabindex=&quot;-1&quot;&gt;API&lt;/h3&gt;
&lt;p&gt;The definition/interface for interaction with something.&lt;/p&gt;
&lt;h3 id=&quot;headless-browser&quot; tabindex=&quot;-1&quot;&gt;Headless browser&lt;/h3&gt;
&lt;p&gt;A browser that is controlled by a server rather than a user. Examples of headless browser tools include puppeteer, selinum and playright.&lt;/p&gt;
&lt;h3 id=&quot;tooling&quot; tabindex=&quot;-1&quot;&gt;Tooling&lt;/h3&gt;
&lt;p&gt;A single or a collection of programs that are used to build a program.&lt;/p&gt;
&lt;h3 id=&quot;hoisting&quot; tabindex=&quot;-1&quot;&gt;Hoisting&lt;/h3&gt;
&lt;p&gt;The use of functions before their definition in the source program.&lt;/p&gt;
&lt;h3 id=&quot;framework&quot; tabindex=&quot;-1&quot;&gt;Framework&lt;/h3&gt;
&lt;p&gt;Something that acts as the entry point to a program. The framework interprets and operates over user code.&lt;/p&gt;
&lt;p&gt;There are several kinds:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Backend/HTTP frameworks&lt;/li&gt;
&lt;li&gt;Frontend frameworks&lt;/li&gt;
&lt;li&gt;Parser frameworks&lt;/li&gt;
&lt;li&gt;Test frameworks&lt;/li&gt;
&lt;li&gt;Benchmark frameworks&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;http-framework&quot; tabindex=&quot;-1&quot;&gt;HTTP framework&lt;/h4&gt;
&lt;p&gt;An abstraction for a server in receiving HTTP requests and returning HTTP responses. Examples: &lt;a href=&quot;https://github.com/expressjs/express&quot;&gt;express&lt;/a&gt;, &lt;a href=&quot;https://github.com/oakserver/oak&quot;&gt;oak&lt;/a&gt; and &lt;a href=&quot;https://github.com/tokio-rs/axum&quot;&gt;axum&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&quot;frontend-framework&quot; tabindex=&quot;-1&quot;&gt;Frontend framework&lt;/h4&gt;
&lt;p&gt;Code that only executes on the frontend&lt;/p&gt;
&lt;h4 id=&quot;fullstack-framework&quot; tabindex=&quot;-1&quot;&gt;Fullstack framework&lt;/h4&gt;
&lt;p&gt;Code that only executes on the frontend and backend&lt;/p&gt;
&lt;h3 id=&quot;library&quot; tabindex=&quot;-1&quot;&gt;Library&lt;/h3&gt;
&lt;p&gt;Something that exposes functions that can be called and returns results.&lt;/p&gt;
&lt;h3 id=&quot;primitive&quot; tabindex=&quot;-1&quot;&gt;Primitive&lt;/h3&gt;
&lt;p&gt;Something of which its internals cannot be read.&lt;/p&gt;
&lt;h3 id=&quot;bundling&quot; tabindex=&quot;-1&quot;&gt;Bundling&lt;/h3&gt;
&lt;p&gt;Concatenation of source code from multiple sources and files into one or more files.&lt;/p&gt;
&lt;h3 id=&quot;dead-code-elimination&quot; tabindex=&quot;-1&quot;&gt;Dead code elimination (DCE)&lt;/h3&gt;
&lt;p&gt;Finding code that is never run or has no effect and making sure its representation doesn&#39;t end up in the final output.&lt;/p&gt;
&lt;h3 id=&quot;tree-shaking&quot; tabindex=&quot;-1&quot;&gt;Tree shaking&lt;/h3&gt;
&lt;p&gt;Tree shaking is a subset of DCE that mostly refers to removing top-level function declarations (from the abstract syntax tree, which is what the tree part refers to).&lt;/p&gt;
&lt;h3 id=&quot;minification&quot; tabindex=&quot;-1&quot;&gt;(whitespace) Minification&lt;/h3&gt;
&lt;p&gt;Remove &lt;strong&gt;unnecessary&lt;/strong&gt; whitespace (new lines, tabs, spaces) from the source.&lt;/p&gt;
&lt;h3 id=&quot;infrastructure&quot; tabindex=&quot;-1&quot;&gt;Infrastructure&lt;/h3&gt;
&lt;p&gt;The whole operation or managing and running the program.&lt;/p&gt;
&lt;h3 id=&quot;standard&quot; tabindex=&quot;-1&quot;&gt;Standard&lt;/h3&gt;
&lt;p&gt;An API that is formalized in a specification and implemented by other parties.&lt;/p&gt;
&lt;h3 id=&quot;type-checking&quot; tabindex=&quot;-1&quot;&gt;Type checking&lt;/h3&gt;
&lt;p&gt;Validating that source code lines up with type definitions.&lt;/p&gt;
&lt;h3 id=&quot;type-annotation&quot; tabindex=&quot;-1&quot;&gt;Type annotation&lt;/h3&gt;
&lt;p&gt;A piece of syntax that associates a type with a term.&lt;/p&gt;
&lt;h3 id=&quot;type-inference&quot; tabindex=&quot;-1&quot;&gt;Type inference&lt;/h3&gt;
&lt;p&gt;Identifying a type without using information from a type annotation.&lt;/p&gt;
&lt;h3 id=&quot;immutable&quot; tabindex=&quot;-1&quot;&gt;Immutable&lt;/h3&gt;
&lt;p&gt;Cannot change&lt;/p&gt;
&lt;h3 id=&quot;mutable&quot; tabindex=&quot;-1&quot;&gt;Mutable&lt;/h3&gt;
&lt;p&gt;Can change&lt;/p&gt;
&lt;h3 id=&quot;cache&quot; tabindex=&quot;-1&quot;&gt;Cache&lt;/h3&gt;
&lt;p&gt;A map like data structure that may or may not contain an already processed or downloaded asset&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Prism Compiler 1.5</title>
    <link href="https://kaleidawave.github.io/posts/prism-one-point-five/"/>
    <updated>2021-03-22T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/prism-one-point-five/</id>
    <summary>Updates to Prism compiler, server-side rendering and why frameworks</summary>
    <content xml:lang="en" type="html">&lt;p&gt;Prism 1.5 is out now. This post goes over the &lt;a href=&quot;https://kaleidawave.github.io/posts/prism-one-point-five/#server-components&quot;&gt;server component&lt;/a&gt; craze, &lt;a href=&quot;https://kaleidawave.github.io/posts/prism-one-point-five/#frontend-frameworks-on-the-backend&quot;&gt;frontend frameworks on the backend&lt;/a&gt;, &lt;a href=&quot;https://kaleidawave.github.io/posts/prism-one-point-five/#why-frameworks&quot;&gt;why frameworks&lt;/a&gt; and the &lt;a href=&quot;https://kaleidawave.github.io/posts/prism-one-point-five/#prism-future&quot;&gt;future of Prism&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Prism is a experimental framework for building web apps which takes declarative templates written in HTML, CSS and JS (similar to Svelte and Vue) and compiles them into small &amp;amp; efficient client and server bundles. It is a research project into some ideas of what I thought could be more efficient isomorphic frameworks.&lt;/p&gt;
&lt;h2 id=&quot;%22server-components%22&quot; tabindex=&quot;-1&quot;&gt;&amp;quot;Server components&amp;quot;&lt;/h2&gt;
&lt;p&gt;Last December there were two big announcements in the world of server rendering. The first was &lt;a href=&quot;https://reactjs.org/blog/2020/12/21/data-fetching-with-react-server-components.html&quot;&gt;React server components&lt;/a&gt; which enables components VDOM content to be rendered on the server. The other was &lt;a href=&quot;https://hotwire.dev/&quot;&gt;hotwire&lt;/a&gt;, which is a set of libraries for adding more interactivity on the page through communicating with the server.&lt;/p&gt;
&lt;p&gt;These two announcements sparked ideas around &lt;em&gt;&amp;quot;server components&amp;quot;&lt;/em&gt; which is a different to the status quo in standard data loading &amp;amp; rendering flow:&lt;/p&gt;
&lt;p&gt;Standard AJAX flow:&lt;/p&gt;
&lt;h3 class=&quot;center&quot;&gt;&lt;p&gt;Read request → JSON → parse → build DOM → append to node&lt;/p&gt;
&lt;/h3&gt;
&lt;p&gt;HTML (or VDOM) over the wire:&lt;/p&gt;
&lt;h3 class=&quot;center&quot;&gt;&lt;p&gt;Read request → append request body as content to a node&lt;/p&gt;
&lt;/h3&gt;
&lt;p&gt;Both are interesting ideas, but looking at both notice that they have constraints and still areas to improve performance. For Prism, I wanted to capitalize on some of the benefits of rendering on the server but in a more flexible and low runtime way.&lt;/p&gt;
&lt;h3 id=&quot;prism-server-components&quot; tabindex=&quot;-1&quot;&gt;Prism server components&lt;/h3&gt;
&lt;p&gt;All frameworks are based on components so to start we can send the following HTML down the wire:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;story-preview&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;buttons&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;disabled&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;amp;#9650;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;disabled&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;amp;#9660;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;https://chartscss.org&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;Charts.css&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            882 points | by&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;/u/pspeter3&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;pspeter3&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;Sun Mar 21 2021 10:37:57 GMT+0000&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;| 1 days ago |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;/i/26494819&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;135 comments&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;story-preview&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;story-preview&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;buttons&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;disabled&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;amp;#9650;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;disabled&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;amp;#9660;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;https://chartscss.org&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;Charts.css&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            882 points | by&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;/u/pspeter3&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;pspeter3&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;Sun Mar 21 2021 10:37:57 GMT+0000&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;| 1 days ago |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;/i/26494819&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;135 comments&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;story-preview&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h6 class=&quot;caption&quot;&gt;&lt;p&gt;(This is an simplified) example from &lt;a href=&quot;https://github.com/kaleidawave/hackernews-prism&quot;&gt;HN prism&lt;/a&gt;&lt;/p&gt;
&lt;/h6&gt;
&lt;p&gt;This example would have been rendered on the server, interpolating data from some source, database etc. The browser then parses the response body and renders the tree in an optimised procedure without running JavaScript. The links are readily clickable and the buttons have a &lt;code&gt;disabled&lt;/code&gt; attribute considering they don&#39;t have any functionality until a JS event listener is attached.&lt;/p&gt;
&lt;p&gt;While this is great there are several scenarios where you want to do some work on the client with the components the server responded with. For example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Upvote post (needs previous value)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.data.score &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Saving title in indexedDB&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;objectStore.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.data.title); &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Making request with data&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`/upvote-post`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    method: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    body: &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;URLSearchParams&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;({&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;postID&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.data.postID})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Upvote post (needs previous value)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.data.score &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Saving title in indexedDB&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;objectStore.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;add&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.data.title); &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Making request with data&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`/upvote-post`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    method: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    body: &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;URLSearchParams&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;({&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;postID&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.data.postID})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;})&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To run the above the client needs to know the value of the data used to render the component&#39;s markup. However, given the server sent markup it&#39;s not known what the data used to render that page on the server looked like. Neither is there any way of guessing, there are eight numbers in the response any of those could be the value for &lt;code&gt;score&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So the answer by many frameworks is to serialize the data used to render that component on the server and include it in the response. The component&#39;s associated data is then deserialized through &lt;code&gt;JSON.parse&lt;/code&gt;. Here is an example of a response with the serialized data:&lt;/p&gt;
&lt;pre&gt;&lt;code data-highlight=&quot;10,20&quot; class=&quot;language-html&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;story-preview&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;buttons&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;disabled&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;amp;#9650;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;disabled&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;amp;#9660;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;https://chartscss.org&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;Charts.css&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            882 points | by&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;/u/pspeter3&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;pspeter3&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;Sun Mar 21 2021 10:37:57 GMT+0000&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;| 1 days ago |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;/i/26494819&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;135 comments&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;data&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;quot;url&amp;quot;: &amp;quot;https://chartscss.org/&amp;quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;quot;title&amp;quot;: &amp;quot;Charts.css&amp;quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;quot;score&amp;quot;: 882,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;quot;by&amp;quot;: &amp;quot;pspeter3&amp;quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;quot;time&amp;quot;: &amp;quot;Sun Mar 21 2021 10:37:57 GMT+0000&amp;quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;quot;id&amp;quot;: 26494819,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;quot;descendants&amp;quot;: 135&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        } &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;story-preview&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;story-preview&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;buttons&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;disabled&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;amp;#9650;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;disabled&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;amp;#9660;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;https://chartscss.org&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;Charts.css&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            882 points | by&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;/u/pspeter3&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;pspeter3&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;Sun Mar 21 2021 10:37:57 GMT+0000&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;| 1 days ago |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;/i/26494819&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;135 comments&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;data&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;quot;url&amp;quot;: &amp;quot;https://chartscss.org/&amp;quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;quot;title&amp;quot;: &amp;quot;Charts.css&amp;quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;quot;score&amp;quot;: 882,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;quot;by&amp;quot;: &amp;quot;pspeter3&amp;quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;quot;time&amp;quot;: &amp;quot;Sun Mar 21 2021 10:37:57 GMT+0000&amp;quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;quot;id&amp;quot;: 26494819,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;quot;descendants&amp;quot;: 135&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        } &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;story-preview&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The problem is now each response is now larger due to the same data now existing both in the markup and in the JSON blob (as shown with the highlighting). This problem is often referred to as the &lt;em&gt;double data&lt;/em&gt; problem. This is especially a problem in VDOM and render to hydrate based frameworks which require all the data to start &lt;a href=&quot;https://kaleidawave.github.io/posts/prism-one-point-five/#foot1&quot;&gt;1&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;hydration&quot; tabindex=&quot;-1&quot;&gt;A different approach to getting state&lt;/h3&gt;
&lt;p&gt;As we have seen just looking at the HTML response it is impossible to pull data from it. But now if I show you the template that was behind what was used to render &lt;code&gt;story-preview&lt;/code&gt;&#39;s HTML then it becomes understandable where those values were interpolated:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;buttons&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;@click&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;upvote&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;amp;#9650;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;@click&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;downvote&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;amp;#9660;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;#if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;url&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;$href&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;url&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;target&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;_blank&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;rel&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;noopener noreferrer&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;{title}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;#else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;{title}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;details&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            {score} points | &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;relative&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;$href&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;`/u/${by}`&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;by {by}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;$title&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;time&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; | {timeFromNowToString(time)} ago | &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;relative&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;$href&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;`/i/${id}`&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;{descendants} comments&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;buttons&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;@click&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;upvote&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;amp;#9650;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;@click&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;downvote&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;amp;#9660;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;#if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;url&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;$href&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;url&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;target&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;_blank&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;rel&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;noopener noreferrer&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;{title}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;#else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;{title}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;details&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            {score} points | &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;relative&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;$href&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;`/u/${by}`&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;by {by}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;$title&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;time&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; | {timeFromNowToString(time)} ago | &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;relative&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;$href&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;`/i/${id}`&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;{descendants} comments&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h6 class=&quot;caption&quot;&gt;&lt;p&gt;From &lt;a href=&quot;https://github.com/kaleidawave/hackernews-prism/blob/4537652060e0011e2e34be5de64036302d739a03/src/views/story-preview.component.prism&quot;&gt;story-preview on hackernews-prism&lt;/a&gt;&lt;/p&gt;
&lt;/h6&gt;
&lt;p&gt;The template reveals what is interpolated where. Comparing it to the previously shown response you can begin to see where values match up to the server response. For example, there is a variable/property named &lt;code&gt;score&lt;/code&gt; which comes before &amp;quot;points&amp;quot;.&lt;/p&gt;
&lt;h3 class=&quot;center&quot;&gt;&lt;p&gt;Knowing how the data maps in the template, a compiler could generate JS getters for retrieving data from the server-rendered DOM.&lt;/p&gt;
&lt;/h3&gt;
&lt;p&gt;In the above example, the title could be retrieved at runtime with the following getter:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;get &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; component.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;h2&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;).innerText &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;get &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; component.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;h2&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;).innerText &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Using this method, state could be brought into JS from the server-rendered content making a JSON blob redundant. No more JSON state leads to a reduction in the bytes sent over the wire.&lt;/p&gt;
&lt;p&gt;And this is how the hydration system in Prism works. The compiler builds a table of bindings in the template. From that, it can generate code similar to the above statement. This same binding table is also used to generate set bindings for reactivity.&lt;/p&gt;
&lt;p&gt;In the following HN clone you can see HTML come down the wire for rendering &lt;code&gt;story-preview&lt;/code&gt; components:&lt;/p&gt;
&lt;p&gt;&lt;video src=&quot;https://kaleidawave.github.io/media/demos/full-server-component-data-hydration.mp4&quot; controls=&quot;&quot; title=&quot;Full server component hydration&quot;&gt;&lt;/video&gt;&lt;/p&gt;
&lt;p&gt;From this, you can see the &lt;code&gt;story-preview&lt;/code&gt; components content is coming from the server as HTML. The rendered markup only contains one instance of the component&#39;s &lt;code&gt;title&lt;/code&gt;, &lt;code&gt;score&lt;/code&gt; and &lt;code&gt;url&lt;/code&gt; properties thus &lt;strong&gt;no double data&lt;/strong&gt;. &lt;code&gt;temp1._d&lt;/code&gt; shows what data the component was given during instantiation but when &lt;code&gt;JSON.stringify(temp1.data)&lt;/code&gt; it evaluates every property by looking it up in the components server rendered DOM. The comments (&lt;code&gt;&amp;lt;!----&amp;gt;&lt;/code&gt;) in the response are to break up text nodes.&lt;/p&gt;
&lt;p&gt;Not only is the state available to the component but is also public to other components. Running &lt;code&gt;JSON.stringify(document.querySelector(&amp;quot;index-page&amp;quot;).data, 0, 4)&lt;/code&gt; should see an object with an array of stories. Those stories exist on the individual components but modifying externally is permitted: &lt;code&gt;document.querySelector(&amp;quot;index-page&amp;quot;).data.stories[2].title = &amp;quot;Hello World&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The resolved data is being pulled from the HTML content of the component when evaluated. I called this implementation &lt;a href=&quot;https://kaleidawave.github.io/posts/jit-hydration&quot;&gt;JIT hydration&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Using this, Prism server components can send standard HTML down and become interactive on the client. A component can mark that its content should be from the server via the &lt;code&gt;@RenderFromEndpoint&lt;/code&gt; decorator which takes a parameterised URL that points to an endpoint that returns the content of the component.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;RenderFromEndpoint&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;/story-preview/:id&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;StoryPreview&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Component&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;IStoryItem&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    ..&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;RenderFromEndpoint&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;/story-preview/:id&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;StoryPreview&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Component&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;IStoryItem&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    ..&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Which is compiled down to:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;render&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`/story-preview/${&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;then&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;resp&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.innerHTML &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; resp.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(); &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;handleEvents&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;?.(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;render&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`/story-preview/${&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;then&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;( &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;resp&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.innerHTML &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; resp.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(); &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;handleEvents&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;?.(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    })&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h6 class=&quot;caption&quot;&gt;&lt;p&gt;No streaming yet &lt;a href=&quot;https://kaleidawave.github.io/posts/prism-one-point-five/#foot4&quot;&gt;4&lt;/a&gt;&lt;/p&gt;
&lt;/h6&gt;
&lt;p&gt;One nicety of this is that it associates data under an identifier. Prism (and most other frameworks) work by a parent component resolving data and then rendering a child component with that data. With this system, components are &lt;em&gt;self-aware&lt;/em&gt; and rerender themselves on updating &lt;code&gt;id&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;video src=&quot;https://kaleidawave.github.io/media/demos/single-server-component.mp4&quot; controls=&quot;&quot; title=&quot;Single server component&quot;&gt;&lt;/video&gt;&lt;/p&gt;
&lt;p&gt;The HTML is coming from a Prism compiled &lt;em&gt;toString&lt;/em&gt; function which given data returns a string of the concatenated component markup. All that is required is hosting an endpoint that calls the generated function and returns the response:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Import prism compiled function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { renderStoryPreviewContent } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;./out/story-preview.prism&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;app.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;/p/:id&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;req&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;res&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    res.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;send&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;renderStoryPreviewContent&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getStoryPreview&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(req.params.id)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;});&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Import prism compiled function&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { renderStoryPreviewContent } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;./out/story-preview.prism&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;app.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;/p/:id&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;req&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;res&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    res.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;send&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;renderStoryPreviewContent&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getStoryPreview&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(req.params.id)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;});&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h6 class=&quot;caption&quot;&gt;&lt;p&gt;As Prism only builds the functions you can build the backend using any node framework or alternatively use them on a serverless function platform&lt;/p&gt;
&lt;/h6&gt;
&lt;p&gt;The server-generated function and hydration system existed for the initial SSR. With the addition of &lt;em&gt;server components&lt;/em&gt;, the efficiencies in these methods now extend to the lifecycle of the page. This system is not a &lt;em&gt;two-way binding system&lt;/em&gt; as the retrieval is only done once. &lt;em&gt;Two-way bindings&lt;/em&gt; often refer to inputs whose value fires updaters when the value of an input changes.&lt;/p&gt;
&lt;p&gt;Events are attached when the custom elements connected callback fires. The compiled implementation finds elements and calls &lt;code&gt;addEventListener&lt;/code&gt;. Unlike others, Prism does not do any sort of rerendering to add event listeners. This results in super quick TTI.&lt;/p&gt;
&lt;p&gt;Prism already had small bundle sizes. Without &lt;em&gt;server components&lt;/em&gt;, the total uncompressed bundle is &lt;code&gt;17kb&lt;/code&gt; and after converting &lt;code&gt;story-preview&lt;/code&gt; and &lt;code&gt;story-page&lt;/code&gt; for their content to be rendered on the server it comes to &lt;code&gt;16.08kb&lt;/code&gt; which is &lt;code&gt;4.76kb&lt;/code&gt; after GZIP. The saving of around ~&lt;code&gt;1kb&lt;/code&gt; is around removing server loading logic and (some) of the render methods for the components. The bundle could be ~25% less if Prism could tree-shake the reactivity logic and minify identifiers.&lt;/p&gt;
&lt;h4 id=&quot;some-other-features-prism-with-its-hydration-implementation-(called-jit-hydration)&quot; tabindex=&quot;-1&quot;&gt;Some other features Prism with its hydration implementation (called JIT hydration)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Getting values from the client is lazy. The get logic is only called when the value is evaluated.&lt;/li&gt;
&lt;li&gt;Getting values on the client is done on a &lt;strong&gt;per-property basis&lt;/strong&gt;. &lt;code&gt;title&lt;/code&gt; can be in the JS runtime but not &lt;code&gt;time&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Caches the returned value to not be a call to the DOM every time.&lt;/li&gt;
&lt;li&gt;Even though the DOM is made up of strings, Prism can convert various types. This is why type declarations are required &lt;a href=&quot;https://kaleidawave.github.io/posts/prism-one-point-five/#foot2&quot;&gt;2&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;using-%40renderfromendpoint-has-the-following-benefits&quot; tabindex=&quot;-1&quot;&gt;Using &lt;code&gt;@RenderFromEndpoint&lt;/code&gt; has the following benefits&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Skipped the parse cycle on the JSON returned from the HN REST API and the runtime creating the nodes on the client which should be a little bit faster.&lt;/li&gt;
&lt;li&gt;Reduced the client logic for getting the data and rendering nodes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;comparisons&quot; tabindex=&quot;-1&quot;&gt;Comparisons&lt;/h3&gt;
&lt;h4 id=&quot;compared-to-react-server-components&quot; tabindex=&quot;-1&quot;&gt;Compared to React server components&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Rendering stateful components (&lt;a href=&quot;https://github.com/josephsavona/rfcs/blob/server-components/text/0000-server-components.md#capabilities--constraints-of-server-and-client-components&quot;&gt;RSC does not allow for stateful components&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Significantly smaller JS size. React starts at &lt;code&gt;133kb&lt;/code&gt; uncompressed, Prism starts at &lt;code&gt;2kb&lt;/code&gt; of JS&lt;/li&gt;
&lt;li&gt;Does not require JS on the backend (see &lt;a href=&quot;https://kaleidawave.github.io/posts/prism-one-point-five/#frontend-frameworks-on-the-backend&quot;&gt;next section&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;One thing I will give React server components is the ability to write &lt;a href=&quot;https://github.com/reactjs/server-components-demo/blob/3a505efea0b1191496a832e23f3de46a0db69915/src/NoteList.server.js#L20&quot;&gt;backend logic in line with the server components&lt;/a&gt; which is kinda neat.&lt;/p&gt;
&lt;h4 id=&quot;compared-to-hotwire&quot; tabindex=&quot;-1&quot;&gt;Compared to Hotwire&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Prism defaults to client rendering. Hotwire has no client rendering implementation,&lt;/li&gt;
&lt;li&gt;Significantly smaller JS size. Stimulus is &lt;code&gt;77.4kb&lt;/code&gt; and Turbo is &lt;code&gt;80.4kb&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Smaller response payloads. Stimulus attribute-based logic is sent down on every response. On the other hand, Prism compiles logic into the JS bundle so the logic size is constant and can cached between requests.&lt;/li&gt;
&lt;li&gt;Stimulus &lt;a href=&quot;https://stimulus.hotwire.dev/handbook/managing-state#reading-initial-state-from-the-dom&quot;&gt;seems to suffer from the double data problem with its &lt;code&gt;data-*-value&lt;/code&gt; attributes&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;json-vs-html&quot; tabindex=&quot;-1&quot;&gt;On JSON vs HTML&lt;/h4&gt;
&lt;p&gt;So the good thing about sending HTML down is that it can be readily placed into the tree without a transformation step. Comparing the sizes: JSON includes the keys whereas Prism&#39;s hydration system encodes the key mapping into the hydration code generation, which is constant for any incoming data. HTML is a data language although data is nested within a bunch of UI markup. For example, on every &lt;code&gt;story-preview&lt;/code&gt; it has to send two buttons for each component although with JSON only the raw data is sent and the buttons are added via constant bundle code.&lt;/p&gt;
&lt;p&gt;Looking at HN front page the average JSON size for &lt;code&gt;story-preview&lt;/code&gt;s was around &lt;code&gt;220bytes&lt;/code&gt; whereas the average inner HTML size was around &lt;code&gt;600bytes&lt;/code&gt;. Thus making HTML around &lt;code&gt;2.5x&lt;/code&gt; larger than its equivalent JSON representation.&lt;/p&gt;
&lt;p&gt;The figures are a little skewed against HTML as Prism includes identifier classes, which could be reduced if Prism moved to an &lt;a href=&quot;https://github.com/kaleidawave/prism/issues/31&quot;&gt;index-based element lookup system&lt;/a&gt;. The size factor varies between components depending on how much of the template is made of data compared to static markup. There is also the fact some of the literal expressions cannot be reversed so a little bit of extra data is added &lt;a href=&quot;https://kaleidawave.github.io/posts/prism-one-point-five/#foot3&quot;&gt;3&lt;/a&gt;. These figures are ignoring compression which may have a disproportionate effect between the formats and may close the size gap. But both formats aren&#39;t great data formats for small efficient data flow. &lt;em&gt;Inspired by &lt;a href=&quot;https://serde.rs/&quot;&gt;serde&lt;/a&gt;&lt;/em&gt;, I have some opinions on how compilers and strong types could be used for making more efficient serialization and deserialization.&lt;/p&gt;
&lt;h4 id=&quot;jit-vs-partial&quot; tabindex=&quot;-1&quot;&gt;On JIT hydration vs Partial hydration&lt;/h4&gt;
&lt;p&gt;One improvement to &lt;em&gt;full&lt;/em&gt; hydration is techniques partial and progressive hydration. Partial hydration seems to benefit render-to-hydrate frameworks (which Prism isn&#39;t) by rerendering only &lt;em&gt;islands&lt;/em&gt; (rather than the whole page) to add interaction. Partial hydration is difficult to implement though as it is difficult to know what portions are interactive and stateful. And although &lt;em&gt;static&lt;/em&gt; regions are now ignored &lt;em&gt;dynamic&lt;/em&gt; regions still suffer from the double data and rerender issue. In this case for HN Prism this means the biggest components &lt;code&gt;story-preview&lt;/code&gt; and &lt;code&gt;story-page&lt;/code&gt; aren&#39;t any more optimized.&lt;/p&gt;
&lt;p&gt;Progressive hydration is incrementally making portions interactive rather than waiting for everything to be processed before event listeners are added.&lt;/p&gt;
&lt;p&gt;However in Prism whether a component is stateful or not it still doesn&#39;t send a JSON blob or &lt;em&gt;rerender&lt;/em&gt;. The state is ultra partial and progressive considering properties are only retrieved when they are being evaluated and only the single property of that object is &lt;em&gt;hydrated&lt;/em&gt; in. &lt;em&gt;I think its reversible hydration system and the code generation around the data is the only way to solve the double data problem for stateful components&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id=&quot;frontend-frameworks-on-the-backend&quot; tabindex=&quot;-1&quot;&gt;Frontend frameworks on the backend&lt;/h3&gt;
&lt;p&gt;One of the arguments behind Hotwire is that its system &lt;em&gt;works&lt;/em&gt; for server-rendered sites built in languages other than JS. This is generally a problem with all front-end frameworks. React, Vue, Angular and Svelte all have some API to render their templates to a string &lt;strong&gt;but&lt;/strong&gt; they are all restricted to the JS language. This is a big gap as there are lots of other backend frameworks and tools for languages not in JS.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;So for Prism, I added the ability to target Rust for its server-side rendering output&lt;/strong&gt;. The HN demo is written as Rust + &lt;code&gt;actix-web&lt;/code&gt; server. Speed was a focus for this site which is why &lt;a href=&quot;https://www.techempower.com/benchmarks/#section=data-r20&amp;amp;hw=ph&amp;amp;test=fortune&quot;&gt;ActixWeb was chosen as it is one of the fastest backend frameworks&lt;/a&gt;. The deserializing from the HN REST API is done with &lt;a href=&quot;https://serde.rs/&quot;&gt;Serde&lt;/a&gt; which is renowned for its speed. And of course, the compiler-based GC heavily optimized Rust language base is key to these results. &lt;a href=&quot;https://medium.com/@maxsparr0w/performance-of-node-js-compared-to-actix-web-37f20810fb1a&quot;&gt;Comparing ActixWeb against Express&lt;/a&gt;, Actix excels in the server framework benchmark. The biggest standout of this article though is that Actix is 6x more efficient than nodejs. This is great for lowering server running costs and most importantly a sixth of the electricity 🌲🌳. Additionally, Prism server-side rendering is also available for nodejs and Deno.&lt;/p&gt;
&lt;p&gt;For those building a Rust REST backend to a client-side rendered site, it means you can add SSR to it without having to deal with both a node and a Rust server and communication between the two.&lt;/p&gt;
&lt;p&gt;Yep, that&#39;s right Rust &lt;svg class=&quot;icon&quot; viewBox=&quot;0 0 24 24&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;&lt;path d=&quot;M23.8346 11.7033l-1.0073-.6236a13.7268 13.7268 0 00-.0283-.2936l.8656-.8069a.3483.3483 0 00-.1154-.578l-1.1066-.414a8.4958 8.4958 0 00-.087-.2856l.6904-.9587a.3462.3462 0 00-.2257-.5446l-1.1663-.1894a9.3574 9.3574 0 00-.1407-.2622l.49-1.0761a.3437.3437 0 00-.0274-.3361.3486.3486 0 00-.3006-.154l-1.1845.0416a6.7444 6.7444 0 00-.1873-.2268l.2723-1.153a.3472.3472 0 00-.417-.4172l-1.1532.2724a14.0183 14.0183 0 00-.2278-.1873l.0415-1.1845a.3442.3442 0 00-.49-.328l-1.076.491c-.0872-.0476-.1742-.0952-.2623-.1407l-.1903-1.1673A.3483.3483 0 0016.256.955l-.9597.6905a8.4867 8.4867 0 00-.2855-.086l-.414-1.1066a.3483.3483 0 00-.5781-.1154l-.8069.8666a9.2936 9.2936 0 00-.2936-.0284L12.2946.1683a.3462.3462 0 00-.5892 0l-.6236 1.0073a13.7383 13.7383 0 00-.2936.0284L9.9803.3374a.3462.3462 0 00-.578.1154l-.4141 1.1065c-.0962.0274-.1903.0567-.2855.086L7.744.955a.3483.3483 0 00-.5447.2258L7.009 2.348a9.3574 9.3574 0 00-.2622.1407l-1.0762-.491a.3462.3462 0 00-.49.328l.0416 1.1845a7.9826 7.9826 0 00-.2278.1873L3.8413 3.425a.3472.3472 0 00-.4171.4171l.2713 1.1531c-.0628.075-.1255.1509-.1863.2268l-1.1845-.0415a.3462.3462 0 00-.328.49l.491 1.0761a9.167 9.167 0 00-.1407.2622l-1.1662.1894a.3483.3483 0 00-.2258.5446l.6904.9587a13.303 13.303 0 00-.087.2855l-1.1065.414a.3483.3483 0 00-.1155.5781l.8656.807a9.2936 9.2936 0 00-.0283.2935l-1.0073.6236a.3442.3442 0 000 .5892l1.0073.6236c.008.0982.0182.1964.0283.2936l-.8656.8079a.3462.3462 0 00.1155.578l1.1065.4141c.0273.0962.0567.1914.087.2855l-.6904.9587a.3452.3452 0 00.2268.5447l1.1662.1893c.0456.088.0922.1751.1408.2622l-.491 1.0762a.3462.3462 0 00.328.49l1.1834-.0415c.0618.0769.1235.1528.1873.2277l-.2713 1.1541a.3462.3462 0 00.4171.4161l1.153-.2713c.075.0638.151.1255.2279.1863l-.0415 1.1845a.3442.3442 0 00.49.327l1.0761-.49c.087.0486.1741.0951.2622.1407l.1903 1.1662a.3483.3483 0 00.5447.2268l.9587-.6904a9.299 9.299 0 00.2855.087l.414 1.1066a.3452.3452 0 00.5781.1154l.8079-.8656c.0972.0111.1954.0203.2936.0294l.6236 1.0073a.3472.3472 0 00.5892 0l.6236-1.0073c.0982-.0091.1964-.0183.2936-.0294l.8069.8656a.3483.3483 0 00.578-.1154l.4141-1.1066a8.4626 8.4626 0 00.2855-.087l.9587.6904a.3452.3452 0 00.5447-.2268l.1903-1.1662c.088-.0456.1751-.0931.2622-.1407l1.0762.49a.3472.3472 0 00.49-.327l-.0415-1.1845a6.7267 6.7267 0 00.2267-.1863l1.1531.2713a.3472.3472 0 00.4171-.416l-.2713-1.1542c.0628-.0749.1255-.1508.1863-.2278l1.1845.0415a.3442.3442 0 00.328-.49l-.49-1.076c.0475-.0872.0951-.1742.1407-.2623l1.1662-.1893a.3483.3483 0 00.2258-.5447l-.6904-.9587.087-.2855 1.1066-.414a.3462.3462 0 00.1154-.5781l-.8656-.8079c.0101-.0972.0202-.1954.0283-.2936l1.0073-.6236a.3442.3442 0 000-.5892zm-6.7413 8.3551a.7138.7138 0 01.2986-1.396.714.714 0 11-.2997 1.396zm-.3422-2.3142a.649.649 0 00-.7715.5l-.3573 1.6685c-1.1035.501-2.3285.7795-3.6193.7795a8.7368 8.7368 0 01-3.6951-.814l-.3574-1.6684a.648.648 0 00-.7714-.499l-1.473.3158a8.7216 8.7216 0 01-.7613-.898h7.1676c.081 0 .1356-.0141.1356-.088v-2.536c0-.074-.0536-.0881-.1356-.0881h-2.0966v-1.6077h2.2677c.2065 0 1.1065.0587 1.394 1.2088.0901.3533.2875 1.5044.4232 1.8729.1346.413.6833 1.2381 1.2685 1.2381h3.5716a.7492.7492 0 00.1296-.0131 8.7874 8.7874 0 01-.8119.9526zM6.8369 20.024a.714.714 0 11-.2997-1.396.714.714 0 01.2997 1.396zM4.1177 8.9972a.7137.7137 0 11-1.304.5791.7137.7137 0 011.304-.579zm-.8352 1.9813l1.5347-.6824a.65.65 0 00.33-.8585l-.3158-.7147h1.2432v5.6025H3.5669a8.7753 8.7753 0 01-.2834-3.348zm6.7343-.5437V8.7836h2.9601c.153 0 1.0792.1772 1.0792.8697 0 .575-.7107.7815-1.2948.7815zm10.7574 1.4862c0 .2187-.008.4363-.0243.651h-.9c-.09 0-.1265.0586-.1265.1477v.413c0 .973-.5487 1.1846-1.0296 1.2382-.4576.0517-.9648-.1913-1.0275-.4717-.2704-1.5186-.7198-1.8436-1.4305-2.4034.8817-.5599 1.799-1.386 1.799-2.4915 0-1.1936-.819-1.9458-1.3769-2.3153-.7825-.5163-1.6491-.6195-1.883-.6195H5.4682a8.7651 8.7651 0 014.907-2.7699l1.0974 1.151a.648.648 0 00.9182.0213l1.227-1.1743a8.7753 8.7753 0 016.0044 4.2762l-.8403 1.8982a.652.652 0 00.33.8585l1.6178.7188c.0283.2875.0425.577.0425.8717zm-9.3006-9.5993a.7128.7128 0 11.984 1.0316.7137.7137 0 01-.984-1.0316zm8.3389 6.71a.7107.7107 0 01.9395-.3625.7137.7137 0 11-.9405.3635z&quot;&gt;&lt;/path&gt;&lt;/svg&gt; server-side rendered web components, never thought you&#39;d see those words together.&lt;/p&gt;
&lt;p&gt;All that is required to render a Prism component/page is to wire up the generated method to an endpoint:&lt;/p&gt;
&lt;pre&gt;&lt;code data-highlight=&quot;1,9&quot; class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Import Prism generated method:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;templates&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;story_page_prism&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;render_story_page_page;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;#[get(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;/i/{storyID}&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;story_page&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;web&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;Path&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;((story_id,))&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;web&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Path&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;i32&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,)&amp;gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;HttpResponse&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; result &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;api&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;items&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get_story&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(story_id)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.await&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(post) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; result {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;HttpResponse&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;content_type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;text/html&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;render_story_page_page&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;post))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;HttpResponse&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;InternalServerError&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;finish&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Import Prism generated method:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;templates&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;story_page_prism&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;render_story_page_page;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;#[get(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;/i/{storyID}&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;story_page&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;web&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;Path&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;((story_id,))&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;web&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Path&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;i32&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,)&amp;gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;HttpResponse&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; result &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;api&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;items&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get_story&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(story_id)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.await&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(post) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; result {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;HttpResponse&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Ok&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;content_type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;text/html&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;render_story_page_page&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;post))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;HttpResponse&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;InternalServerError&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;finish&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The fact that React server components were restricted to a node backend was discussed in the &lt;a href=&quot;https://github.com/reactjs/rfcs/pull/188&quot;&gt;comments of the RFC&lt;/a&gt;. Without embedding v8 and making calls it looks pretty distant that React SSR could be fully functioning on non-js backends. The difficulty with embedding v8 is that you lose strong typing from Typescript.&lt;/p&gt;
&lt;p&gt;I should also mention WASM and Rust-based &amp;quot;frontend-frameworks&amp;quot; &lt;a href=&quot;https://yew.rs/&quot;&gt;yew&lt;/a&gt;, &lt;a href=&quot;https://github.com/chinedufn/percy&quot;&gt;percy&lt;/a&gt; &amp;amp; &lt;a href=&quot;https://github.com/seed-rs/seed&quot;&gt;seed&lt;/a&gt; here. They look very interesting, make effective use of procedural macros, have Rust SSR support and are the first real way to write DOM-based client-side code in a different language to JavaScript (other than languages that compile to JavaScript). However, WASM has a few disadvantages for the client-side apps. Firstly the size of the WASM bytecode seems to be larger than if the logic was written in JS. I don&#39;t quite know the specifics of WASM bytecode but from machine bytecode know that things like generic implementations, bundling standard library and inlining bumps up the size. All of which serving JS doesn&#39;t suffer from. Yew states that its example  bundle is ~&lt;code&gt;100kb&lt;/code&gt; which is similar in size to React which isn&#39;t great for slower connections. Also, the component sizes are likely to be larger than if they were written in JS. Yes, their bundle is faster to parse and compile but TTI is hampered from loading over the network. Secondly, they seem to use VDOM and diffing (rather than a compiled reactivity approach) so while being close to the metal they still generally do more computation vs direct compiled setters. That also means they probably suffer from the double data issues that Prism escapes. Also, the fact that WASM can&#39;t call arbitrary JS methods and instead has to be passed them. So fetching etc still requires writing JS and passing references to the instance. Cool at the moment for canvas rendering etc but generally not the silver bullet for JS-based frontend frameworks.&lt;/p&gt;
&lt;p&gt;For Prism the most promising feature with WASM is the available runners. If Prism could compile SSR functions for WASM then it could be used with the &lt;a href=&quot;https://github.com/wasmerio/wasmer-python&quot;&gt;Python runner&lt;/a&gt; and wouldn&#39;t have separate compiler outputs. Untested but I think Prism&#39;s &lt;a href=&quot;https://avacariu.me/writing/2014/calling-rust-from-python&quot;&gt;rust output as binary could be called from the Python runtime&lt;/a&gt; or any other language that can call C-like code.&lt;/p&gt;
&lt;h3 id=&quot;reflection-on-prism&quot; tabindex=&quot;-1&quot;&gt;Reflection on Prism&lt;/h3&gt;
&lt;p&gt;With Prism I took a lot of the problems around frontend frameworks today into account with the design. I hope I at least made a dent in some of these issues:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Double data from SSR&lt;/li&gt;
&lt;li&gt;SSR in languages other than JavaScript (in this case Rust)&lt;/li&gt;
&lt;li&gt;The large size from a frameworks runtime&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;At this point, it seems necessary to mention why frameworks? and why plain JS or no build step is insufficient in many cases for production sites.&lt;/p&gt;
&lt;h3 id=&quot;why-frameworks&quot; tabindex=&quot;-1&quot;&gt;Why frameworks?&lt;/h3&gt;
&lt;p&gt;Frameworks generally implement a single declarative way to mark that this variable/data/state is interpolated here. Reactivity mechanisms ensure that the view is always up to date with the current value of the variable/data/state. Generally HTML doesn&#39;t have a way to express a binding with JS. So updating the view is done imperatively:&lt;/p&gt;
&lt;pre&gt;&lt;code data-highlight=&quot;7,18&quot; class=&quot;language-js&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;customElements.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;define&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;counter-component&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;HTMLElement&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;counter&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;connectedCallback&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; document.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;createElement&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;h1&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            h1.innerHTML &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.counter;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; document.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;createElement&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;button&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            button.innerHTML &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;+&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            button.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;click&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;incrementCounter&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(h1, button);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;incrementCounter&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.counter &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;h1&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;).innerHTML &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.counter;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;counterComponent&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; document.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;createElement&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;counter-component&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;document.body.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(counterComponent);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;customElements.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;define&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;counter-component&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;HTMLElement&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;counter&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;connectedCallback&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; document.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;createElement&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;h1&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            h1.innerHTML &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.counter;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; document.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;createElement&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;button&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            button.innerHTML &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;+&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            button.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;addEventListener&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;click&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, () &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;incrementCounter&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            });&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(h1, button);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;incrementCounter&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.counter &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;h1&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;).innerHTML &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.counter;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;counterComponent&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; document.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;createElement&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;counter-component&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;document.body.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(counterComponent);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h6 class=&quot;caption&quot;&gt;&lt;p&gt;(excludes cleanup)&lt;/p&gt;
&lt;/h6&gt;
&lt;p&gt;Here the interpolation of &lt;code&gt;this.counter&lt;/code&gt; is done imperatively and due to this, it requires writing the interpolation logic twice. Writing twice is a little time-consuming but the worst effect is that the logic is split up. If the first part is modified for example &lt;code&gt;h1&lt;/code&gt; tag is changed to &lt;code&gt;h5&lt;/code&gt; then the second part is broken and it&#39;s not clear for a linter to pick this up. The &lt;em&gt;desync&lt;/em&gt; issue here is manageable but when you have lots of components with lots of interpolation spread across a large project with lots of contributors it gets difficult to manage. There is also the fact that the imperative calls are quite distant from the declarative design of the HTML language and reading &amp;amp; processing the above is more difficult. However, the lack of interpolation synchronization only gets worse...&lt;/p&gt;
&lt;h4 id=&quot;ssr&quot; tabindex=&quot;-1&quot;&gt;Universality/SSR&lt;/h4&gt;
&lt;p&gt;The reactivity issue is further amplified when work is shared between the client and server. For this example, a &lt;em&gt;&amp;quot;post&amp;quot;&lt;/em&gt; is sent down with some interpolated data.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;server.js&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;res.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;send&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;    &amp;lt;h1&amp;gt;${&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;postTitle&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;}&amp;lt;/h1&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;    &amp;lt;button id=&amp;quot;upvote-button&amp;quot;&amp;gt;Upvote post&amp;lt;/button&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;    &amp;lt;span id=&amp;quot;upvotes&amp;quot;&amp;gt;${&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;upvotes&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;}&amp;lt;/span&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;res.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;send&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;    &amp;lt;h1&amp;gt;${&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;postTitle&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;}&amp;lt;/h1&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;    &amp;lt;button id=&amp;quot;upvote-button&amp;quot;&amp;gt;Upvote post&amp;lt;/button&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;    &amp;lt;span id=&amp;quot;upvotes&amp;quot;&amp;gt;${&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;upvotes&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;}&amp;lt;/span&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And after some action on the front-end incrementing &lt;code&gt;this.upvotes&lt;/code&gt;. Updating the text of the span is done with:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;client.js&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;document.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;span#upvotes&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;).innerText &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.upvotes &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;document.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;span#upvotes&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;).innerText &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.upvotes &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is not great because there is a loose reference to &lt;code&gt;span#upvotes&lt;/code&gt;. The server response may be changed to use &lt;code&gt;p&lt;/code&gt; instead of a &lt;code&gt;span&lt;/code&gt; and now the &lt;code&gt;querySelector&lt;/code&gt; call returns null. It is not easy to find the issue and often ends up in a &amp;quot;spot the difference&amp;quot; or &amp;quot;where&#39;s Wally&amp;quot; scenario across separate files. I have found this on large projects where I go to change or add a button and now have to find out what code was relying on that button and what that affects. This problem is amplified when there are tens of pages and hundreds of places where things are interpolated and events are connected.&lt;/p&gt;
&lt;h5 id=&quot;checking&quot; tabindex=&quot;-1&quot;&gt;Checking&lt;/h5&gt;
&lt;p&gt;There is also the fact that the above server code is a raw string literal. It does not check if it is valid HTML at compile time (some templating languages may do, not quite sure) so I have often lost time after writing something like &lt;code&gt;&amp;lt;h1 ${someX}&amp;lt;/h1&amp;gt;&lt;/code&gt;. With Prism it will always concatenate to valid HTML and as a compiler, it also catches syntax errors when parsing templates. The Svelte framework takes this checking a step further linting the template with rules to ensure accessible HTML. This is only really possible with the template DSL of Svelte as a template literal can still be valid without knowing what is interpolated.&lt;/p&gt;
&lt;p&gt;The other thing Prism does is add the &lt;code&gt;disabled&lt;/code&gt; attribute to buttons with events which it then removes on adding event listeners. Also, the above snippet is susceptible to XSS scripting attacks. Prism (and other template languages) wrap all interpolations in escape-safe calls. The other thing is Prism auto generates non-clashing identifiers. The incrementing example above would break if I added a new element on the page with an identifier &lt;code&gt;#upvotes&lt;/code&gt;.&lt;/p&gt;
&lt;h5 id=&quot;lists&quot; tabindex=&quot;-1&quot;&gt;Lists&lt;/h5&gt;
&lt;p&gt;With lists, you may want to render the first 10 items in the server responses and later add more in an infinite style way (the same way Twitter and Instagram feeds work). So on the server, I may write a function that renders an element of a list:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;renderListItemToString&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;IPost&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; { .. }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;renderListItemToString&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;IPost&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; { .. }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However now on the client if I wanted to append a new item the &lt;code&gt;renderListItemToString&lt;/code&gt; is only available on the backend (not the frontend). With a framework that has or compiles multiple functions depending on runtime the same list item elements can be generated on both the frontend and backend. I guess this is an advantage of server components and Turbo where the frontend function is an alias for calling the same function on the backend under the same source.&lt;/p&gt;
&lt;h4 id=&quot;single-source&quot; tabindex=&quot;-1&quot;&gt;Single source&lt;/h4&gt;
&lt;p&gt;So frameworks implement some sort of single source. For example in Prism:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;{postTitle}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;@click&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;upvotePost&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;Upvote post&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;{upvotes}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    public &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PostData&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;postTitle&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;upvotes&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    @&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;WithCapacity&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Post&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Component&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PostData&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;upvotePost&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.data.upvotes &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;{postTitle}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;@click&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;upvotePost&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;Upvote post&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;{upvotes}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    public &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PostData&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;postTitle&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;upvotes&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    @&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;WithCapacity&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Post&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Component&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PostData&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;upvotePost&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.data.upvotes &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The template is declarative. It abstracts on the imperative &lt;code&gt;document.createElement&lt;/code&gt; and &lt;code&gt;attachEventListener&lt;/code&gt; calls. The template is much more akin to HTML and understanding the structure of this component is more accessible. The span &amp;lt;-&amp;gt; &lt;code&gt;upvotes&lt;/code&gt; binding is only written once. And so if &lt;code&gt;span&lt;/code&gt; was changed to &lt;code&gt;p&lt;/code&gt; there are no other handwritten references of this binding and compiling would take care of updating all references to span with references to the &lt;code&gt;p&lt;/code&gt; element. For full reactivity and JIT hydration, Prism will take the single source and generate different code to handle for each case. These would be tricky to manage if written manually. For example, the upvotes binding eventually ends up in four places:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;client.js&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code data-highlight=&quot;2,8,9&quot; class=&quot;language-js&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Initial render&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;render&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(.., &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;h&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;span&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, {class: &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;p120&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.data.upvotes))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Reactive bindings&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;bindings &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    ..&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    upvotes: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() { &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;parseInt&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getElem&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;p120&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;).innerHTML); },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) { &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getElem&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;p120&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;).innerHTML &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; value; },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Initial render&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;render&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(.., &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;h&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;span&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, {class: &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;p120&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.data.upvotes))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Reactive bindings&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;bindings &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    ..&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    upvotes: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() { &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;parseInt&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getElem&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;p120&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;).innerHTML); },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) { &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getElem&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;p120&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;).innerHTML &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; value; },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;server.rs&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code data-highlight=&quot;8&quot; class=&quot;language-rust&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;PostData&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    postTitle&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    upvotes&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;f64&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;render_post&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(post&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;IPost&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; acc &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;from_capacity&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    acc&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;upvotes&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;to_string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;..&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    acc;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;PostData&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    postTitle&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    upvotes&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;f64&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;fn&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;render_post&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(post&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;IPost&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;mut&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; acc &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;from_capacity&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    acc&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;push_str&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;upvotes&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;to_string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;..&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    acc;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In terms of doing this, getting the biggest abstraction at a low cost requires a build step to do static analysis on ASTs and do specific code generation.&lt;/p&gt;
&lt;p&gt;The other benefit of Prism, Svelte and Vue is that they use single-file components. These allow you to write CSS in the same file as the components.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;..&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;..&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;style&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;.container&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;width&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;80&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;h&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;1 {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;color&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;red&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;style&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;..&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;..&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;style&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;.container&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;width&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;80&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;h&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;1 {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;color&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;red&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;style&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h6 class=&quot;caption&quot;&gt;&lt;p&gt;There are many benefits in readability in having CSS alongside the components. Prism and others also automatically scope classes so that other &lt;code&gt;div.container&lt;/code&gt;s are not affected outside of the component&lt;/p&gt;
&lt;/h6&gt;
&lt;h2 id=&quot;other-prism-changes&quot; tabindex=&quot;-1&quot;&gt;Other Prism changes&lt;/h2&gt;
&lt;h3 id=&quot;observable-date-instances&quot; tabindex=&quot;-1&quot;&gt;Observable Date instances&lt;/h3&gt;
&lt;p&gt;One design of Prism is to effectively act as if the DOM was a result of a &lt;em&gt;getter&lt;/em&gt; and the view should always be 1:1 to the value of the evaluated getter&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;MyComponent&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;date&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;content&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`&amp;lt;h5&amp;gt;${&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;}&amp;lt;/h5&amp;gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    } &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;addMinuteToDate&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.date.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;setMinute&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.date.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getMinute&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;MyComponent&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;date&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;content&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`&amp;lt;h5&amp;gt;${&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;formatDate&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;}&amp;lt;/h5&amp;gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    } &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;addMinuteToDate&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.date.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;setMinute&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.date.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getMinute&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Frameworks have something where you tell it to update with the new state. React&#39;s &lt;code&gt;setState&lt;/code&gt; is an abstraction over rerendering the DOM as React doesn&#39;t have a concept of state. It should be &lt;code&gt;rerenderWithTheseValues&lt;/code&gt;. Simply setting a property in a React will not make the view update.&lt;/p&gt;
&lt;p&gt;Svelte is better in that its state updates are triggered around the assignment operator. Which is a step towards more &amp;quot;native&amp;quot; JavaScript. However, there are still issues around internal changes. You cannot use push in Svelte, instead &lt;code&gt;x = [...x, newItem]&lt;/code&gt; is required for the compiler to realise an update has happened. This is also the case for the &lt;code&gt;Date&lt;/code&gt; instance, calling &lt;code&gt;setMonth&lt;/code&gt; etc does not cause the view to be updated. With Prism I wanted to allow internal mutation in the same way JS works. So I implemented this for &lt;code&gt;Date&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;video src=&quot;https://kaleidawave.github.io/media/demos/date-reactivity-demo.mp4&quot; controls=&quot;&quot; title=&quot;Date reactivity&quot;&gt;&lt;/video&gt;&lt;/p&gt;
&lt;p&gt;(&lt;a href=&quot;https://github.com/kaleidawave/prism/blob/aa6a4f4e7c755076666efc16a984a663885e1674/src/bundle/observable.ts#L159&quot;&gt;just don&#39;t look how I implemented this&lt;/a&gt;)&lt;/p&gt;
&lt;h3 id=&quot;internal-updates&quot; tabindex=&quot;-1&quot;&gt;Internal updates&lt;/h3&gt;
&lt;p&gt;In Prism 1.5.0 the Rust SSR compilation was improved so the server render functions now append to the same buffer. The buffer can have initial capacity using the new decorator &lt;code&gt;@WithCapacity(x)&lt;/code&gt;. Setting the value can improve SSR performance by avoiding reallocations. There are also some unnecessary &lt;code&gt;to_string&lt;/code&gt; calls on Strings which have been removed with the help of types.&lt;/p&gt;
&lt;p&gt;Text can now be interpolated when alongside other tags. There are fixes for getting data on nullable nodes and there has been A lot of work behind the scenes to allow for Prism components to be compiled on the browser.&lt;/p&gt;
&lt;h3 id=&quot;prism-future&quot; tabindex=&quot;-1&quot;&gt;Future&lt;/h3&gt;
&lt;p&gt;Prism is not designed to be the next new framework. Instead, it is an implementation in attempting to experiment on improving the implementations of SSR and hydration in current popular frontend frameworks.&lt;/p&gt;
&lt;p&gt;One thing is that it unfortunately has the same name as the syntax highlighting library &lt;a href=&quot;https://github.com/PrismJS/prism/&quot;&gt;prism.js&lt;/a&gt; which may cause some confusion. When I named the framework, &amp;quot;Prism&amp;quot; was meant to depict the single source that is &lt;em&gt;split&lt;/em&gt; into various paths (CSR, SSR, bindings, hydration logic, etc). I wasn&#39;t aware of &lt;code&gt;prism.js&lt;/code&gt; and its prevalence until shortly after releasing it under that name. It also unintentionally has an extremely similar logo to the database ORM &lt;a href=&quot;https://github.com/prisma/prisma&quot;&gt;prisma&lt;/a&gt;. If interest were to pick up then I may make features more reliable and release it under a new name.&lt;/p&gt;
&lt;p&gt;The compiler is a little rough around the edges. It is not intended for production but if you want to try out JIT hydration or Rust compilation you can try the &lt;a href=&quot;https://github.com/kaleidawave/prism/blob/main/docs/quickstart.md&quot;&gt;quick start&lt;/a&gt; or fork the &lt;a href=&quot;https://github.com/kaleidawave/hackernews-prism&quot;&gt;HN repo&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;footnotes&quot; tabindex=&quot;-1&quot;&gt;Footnotes 📜&lt;/h3&gt;
&lt;h6 id=&quot;foot1&quot;&gt;(1)&gt;&lt;p&gt;Render to hydrate&lt;/p&gt;
&lt;/h6&gt;
&lt;p&gt;For event listeners to be added the runtime needs to find the elements first. Many frontend frameworks do this via &amp;quot;rendering&amp;quot; their tree and comparing the result with the markup. Therefore &lt;strong&gt;all&lt;/strong&gt; the data is hydrated at the start of page load.&lt;/p&gt;
&lt;h6 id=&quot;foot2&quot;&gt;(2)&gt;&lt;p&gt;Types&lt;/p&gt;
&lt;/h6&gt;
&lt;p&gt;All values represented in the DOM are strings. &lt;code&gt;innerText&lt;/code&gt; is string, &lt;code&gt;getAttribute()&lt;/code&gt; returns string. So when getting the value of score from the server-rendered markup it needs to be converted to &lt;code&gt;number&lt;/code&gt; instance first. In order to know what instance to convert it to Prism requires to know the type. This is done using a TypeScript generic argument on the class:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// @useRustStatement #[derive(Clone, Debug, serde::Deserialize)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;IStoryItem&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;by&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;score&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    @&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;useRustStatement&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`#[serde(default)]`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;descendants&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// Number of kids&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    @&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;useRustStatement&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`#[serde(with = &amp;quot;chrono::serde::ts_seconds&amp;quot;)]`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    @&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;useRustStatement&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`#[serde(default)]`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;kids&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// This is &amp;quot;type&amp;quot; in the HN API but Rust does not like &amp;quot;type&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    @&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;useRustStatement&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`#[serde(rename(deserialize = &amp;quot;type&amp;quot;))]`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;storyType&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;job&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;story&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;comment&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;poll&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;pollopt&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;?:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// @useRustStatement #[derive(Clone, Debug, serde::Deserialize)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;IStoryItem&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;by&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;score&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    @&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;useRustStatement&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`#[serde(default)]`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;descendants&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// Number of kids&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    @&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;useRustStatement&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`#[serde(with = &amp;quot;chrono::serde::ts_seconds&amp;quot;)]`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Date&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    @&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;useRustStatement&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`#[serde(default)]`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;kids&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// This is &amp;quot;type&amp;quot; in the HN API but Rust does not like &amp;quot;type&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    @&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;useRustStatement&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`#[serde(rename(deserialize = &amp;quot;type&amp;quot;))]`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;storyType&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;job&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;story&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;comment&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;poll&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;pollopt&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;?:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h6 class=&quot;caption&quot;&gt;&lt;p&gt;The types are also used to build Rust &lt;code&gt;struct&lt;/code&gt; definitions for definite types on their render methods. &lt;code&gt;@useRustStatement&lt;/code&gt; allows for adding attributes to the struct members.&lt;/p&gt;
&lt;/h6&gt;
&lt;h6 id=&quot;foot3&quot;&gt;(3)&gt;&lt;p&gt;Non reversible expressions&lt;/p&gt;
&lt;/h6&gt;
&lt;p&gt;Some expressions cannot be reversed. For example, the &lt;code&gt;date&lt;/code&gt; in markup is rendered as a relative string. From &lt;code&gt;&amp;quot;1 day ago&amp;quot;&lt;/code&gt; it isn&#39;t possible to construct a &lt;code&gt;Date&lt;/code&gt; instance of that value as it could be any hour, minute etc of the previous day. There are a possible &lt;code&gt;86400000&lt;/code&gt; different &lt;code&gt;Date&lt;/code&gt; objects that could have been rendered to say &lt;code&gt;&amp;quot;1 day ago&amp;quot;&lt;/code&gt;. Information has been lost in converting it into its formatted string. So instead an ISO string representation of that &lt;code&gt;Date&lt;/code&gt; is added as an attribute on one of the elements so the hydration logic can do &lt;code&gt;return new Date(elem.getAttribute())&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Prism can reverse some expressions e.g. from &lt;code&gt;/i/${id}&lt;/code&gt; it produces this expression &lt;code&gt;result.slice(3)&lt;/code&gt;. See &lt;a href=&quot;https://github.com/kaleidawave/prism/issues/11&quot;&gt;this issue&lt;/a&gt; for further details.&lt;/p&gt;
&lt;h6 id=&quot;foot4&quot;&gt;(4)&gt;&lt;p&gt;Streaming&lt;/p&gt;
&lt;/h6&gt;
&lt;p&gt;Currently, the response from SSR is buffered and sent and appended as one. This isn&#39;t great as the server could start sending the first part of the markup while it is waiting for the data source to respond. The first thing is that Prism doesn&#39;t have a way to mark async data (Svelte has &lt;code&gt;await&lt;/code&gt; blocks and &lt;a href=&quot;https://markojs.com/&quot;&gt;marko&lt;/a&gt; has &lt;code&gt;Await&lt;/code&gt; elements) that are probably needed to do static analysis. The second is that &lt;a href=&quot;https://web.dev/fetch-upload-streaming/&quot;&gt;fetch response streaming is not yet stable&lt;/a&gt;. Most streaming solutions currently use web sockets. Streaming content on initial page load is a feature by the browser but doing it after the page loads for web components is only possible via &lt;a href=&quot;https://jakearchibald.com/2016/fun-hacks-faster-content/&quot;&gt;this slight hack&lt;/a&gt;. Also, Rust generators (which would be preferred) for the compiled SSR functions &lt;a href=&quot;https://github.com/rust-lang/rust/issues/43122&quot;&gt;are not yet stable&lt;/a&gt;, &lt;em&gt;(although something could be done with closures)&lt;/em&gt;. Hacker News is a bad example due to not having a direct request to their database and the latency effects from buffering are visible. Streaming is planned for the future but not available in this release.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>JIT Hydration</title>
    <link href="https://kaleidawave.github.io/posts/jit-hydration/"/>
    <updated>2020-11-24T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/jit-hydration/</id>
    <summary>JIT hydration is a technique for incrementally hydrating state from the HTML when building universally rendered sites</summary>
    <content xml:lang="en" type="html">&lt;p&gt;What is hydration? It typically refers to the act of making statically rendered markup interactive.&lt;/p&gt;
&lt;p&gt;But what is interactive? Interactivity is added by attaching event listeners and setting the scene for those listeners to be able to change the view. The step aims to make the page indifferent to it being client-side rendered.&lt;/p&gt;
&lt;p&gt;So how do frameworks add event listeners to the existing markup?&lt;/p&gt;
&lt;p&gt;Many frameworks do this by rendering the markup again. The rendering identifies where the elements with listeners are. And from knowing their position they can attach to existing markup. To render the application first requires hydrating the state. For example with React:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/demos/react-hydration.gif&quot; alt=&quot;react-hydration&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(Something like that I think)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;But the issue here is to add the event listeners the component needs to be &lt;em&gt;rendered&lt;/em&gt; &lt;strong&gt;and for it to be rendered it needs to its data/state&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This is where hydration comes in. To render this &amp;quot;frame&amp;quot; it needs some data.&lt;/p&gt;
&lt;p&gt;Standard client-side rendered sites would make a HTTP request to the backend API to get the data on the initial mount. But this is a separate request, there may have been changes to the data in the time between rendering the page, getting it to the client and the client parsing and running the script. The difference in the data could break things. The other issue is that this is a totally new request and (without backend caching) would have to make another request to the database which is expensive.&lt;/p&gt;
&lt;h4 id=&quot;double-data&quot; tabindex=&quot;-1&quot;&gt;So the solution a lot of frameworks use is to send the data down as a JSON blob with the request&lt;/h4&gt;
&lt;pre&gt;&lt;code data-highlight=&quot;6,15&quot; class=&quot;language-html&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;head&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        window.__data__ &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;JSON&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;parse&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;            {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;                &amp;quot;articles&amp;quot;: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;                    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;                        &amp;quot;title&amp;quot;: &amp;quot;Tips for performant TypeScript&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;                ]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;        `&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;head&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;Tips for performant TypeScript&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;head&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        window.__data__ &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;JSON&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;parse&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;            {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;                &amp;quot;articles&amp;quot;: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;                    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;                        &amp;quot;title&amp;quot;: &amp;quot;Tips for performant TypeScript&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;                    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;                ]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;        `&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;head&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;Tips for performant TypeScript&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h5 id=&quot;this-has-some-overhead-because-the-data-is-effectively-sent-down-twice&quot; tabindex=&quot;-1&quot;&gt;&lt;a href=&quot;https://youtu.be/CQaDl9Fu0W0?t=365&quot;&gt;This has some overhead because the data is effectively sent down twice&lt;/a&gt;&lt;/h5&gt;
&lt;p&gt;There is also the fact JSON is difficult to work with due to its difficulty in representing complex types such as &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date&quot;&gt;&lt;code&gt;Date&lt;/code&gt;&lt;/a&gt; and other things like cyclic references etc. Also, some JSON blobs are quite large especially if there are long lists of objects. And using raw JS object literals can be slow &lt;a href=&quot;https://www.youtube.com/watch?v=ff4fgQxPaO0&quot;&gt;due to the way they are parsed&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Additionally, some parts of this object were not used in the render and so will not be needed in the re-render. In a large number of cases, this object contains more data than was needed.&lt;/p&gt;
&lt;p&gt;The &#39;Time to interactive&#39; measurement can be decreased because the whole state has to be parsed evaluated and the application rendered before a single event listener has been added. This problem also occurs for static site generation as well. Any sort of process of generating markup beforehand (which is beneficial) where that markup needs client-side reactivity needs to do some sort of hydration.&lt;/p&gt;
&lt;p&gt;This issue is something framework authors and developers are aware of and actively working on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://twitter.com/youyuxi/status/1274834284826763265&quot;&gt;Evan You, Creator of Vue&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developers.google.com/web/updates/2019/02/rendering-on-the-web#rehydration-issues&quot;&gt;Google post on the issue&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href=&quot;https://medium.com/@luke_schmuke/how-we-achieved-the-best-web-performance-with-partial-hydration-20fab9c808d5#94ad&quot;&gt;Partial hydration&lt;/a&gt; is one technique that is being considered. Using partial hydration in an app you split up the application so there are multiple sources. Instead of a single &lt;code&gt;hydrate&lt;/code&gt; call, there are multiple invocations under some components. This way you can prioritize reactive elements and ignore static elements. See popular RFCs from these frameworks; &lt;a href=&quot;https://github.com/sveltejs/svelte/issues/4308&quot;&gt;Svelte&lt;/a&gt;, &lt;a href=&quot;https://github.com/facebook/react/pull/14717&quot;&gt;react&lt;/a&gt;, &lt;a href=&quot;https://github.com/angular/angular/issues/13446&quot;&gt;angular&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;But most implementations seem quite manual to implement. It also seems difficult to how this plays out with what is a static element and what needs to be reactive.&lt;/p&gt;
&lt;h3 id=&quot;jit-hydration&quot; tabindex=&quot;-1&quot;&gt;But today I&#39;ll introduce a different approach: JIT hydration&lt;/h3&gt;
&lt;p&gt;The fastest interactivity would be prioritizing adding event listeners. A non VDOM system doesn&#39;t need state to find event listeners. Instead, the framework&#39;s compiler could mark elements with event listeners and these could be added with the combination of local state in custom elements and &lt;code&gt;this.querySelector(&amp;quot;#element_identifier&amp;quot;).addEventListener&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The state still needs to be hydrated to be accessible at the JS runtime. &lt;strong&gt;But to prevent the double data problem the values would be hydrated from the rendered DOM and they could be done on access just in time (JIT)&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This is what I have implemented into my framework &lt;a href=&quot;https://github.com/kaleidawave/prism&quot;&gt;Prism&lt;/a&gt;. One of the features is JIT hydration:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/demos/prism-hydration.gif&quot; alt=&quot;prism-hydration&quot; /&gt;&lt;/p&gt;
&lt;h4 id=&quot;demo&quot; tabindex=&quot;-1&quot;&gt;And this is working quite well here on my &lt;a href=&quot;https://github.com/kaleidawave/hackernews-prism&quot;&gt;Hacker News clone&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/demos/hackernews-prism-hydration.gif&quot; alt=&quot;hackernews-prism-hydration&quot; /&gt;&lt;/p&gt;
&lt;p&gt;It is compiled with the Prism compiler and all the rendered data can be JIT hydrated while none of the payloads send any sort of JS(ON) state blobs.&lt;/p&gt;
&lt;p&gt;You can read more about the Hacker News clone &lt;a href=&quot;https://kaleidawave.github.io/posts/hackernews-clone-prism-rust&quot;&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;JIT hydration has the effect of a fully hydrated page but at a lower cost to the client.&lt;/p&gt;
&lt;h3 id=&quot;benefits&quot; tabindex=&quot;-1&quot;&gt;So what are the features and benefits of Prism&#39;s JIT hydration?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;On load, the only logic is attaching event listeners. This leads to a decrease in the &#39;time-to-interactive&#39; (TTI)&lt;/li&gt;
&lt;li&gt;Loading state is deferred until needed&lt;/li&gt;
&lt;li&gt;Loading in state is done on a per-property basis rather than everything at once so the lazy-ness does not come at a significant cost&lt;/li&gt;
&lt;li&gt;Smaller HTML payload sizes due to not needing JSON state&lt;/li&gt;
&lt;li&gt;Resolved complications for objects that cannot be represented in JSON (looking at you &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date&quot;&gt;&lt;code&gt;Date&lt;/code&gt;&lt;/a&gt; 👀), cycles etc&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Although values in the DOM are all strings, Prism converts the strings to the correct types. As can be seen from the &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;score&lt;/code&gt; values on each story in the state. Values are also cached after being pulled in during hydration, so later accessors don&#39;t have to go back to the DOM. The logic for doing this is invariant to the page and so JS is cached between requests. The JSON blob is different and so is sent down on every new full page.&lt;/p&gt;
&lt;div class=&quot;parralel&quot;&gt;
            &lt;div&gt;&lt;h3 id=&quot;json-based-hydration&quot; tabindex=&quot;-1&quot;&gt;JSON based hydration&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;title&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;*post title*&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;data&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        {..., &amp;quot;title&amp;quot;: &amp;quot;*post title*&amp;quot;, ...}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            document.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getElementById&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;data&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;JSON&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;parse&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(data.textContent);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;title&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;*post title*&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;data&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        {..., &amp;quot;title&amp;quot;: &amp;quot;*post title*&amp;quot;, ...}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            document.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getElementById&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;data&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;JSON&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;parse&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(data.textContent);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Data twice in response, parse done after load&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
            &lt;div&gt;
&lt;h3 id=&quot;with-prism-compiler&quot; tabindex=&quot;-1&quot;&gt;With Prism compiler&lt;/h3&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;title&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;p2312&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;*post title*&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;element&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    document.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;p2312&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; element.innerText;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;title&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;p2312&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;*post title*&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;element&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    document.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;p2312&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; element.innerText;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;Data loaded from markup and only when requested&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
        &lt;/div&gt;
&lt;h3 id=&quot;conclusion&quot; tabindex=&quot;-1&quot;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;While it has its benefits, JIT hydration is difficult to implement. For it to work effectively there needs to be more analysis and code generation work done at build time. It needs to be established where the state is interpolated and how that can be reversed to be read at runtime.&lt;/p&gt;
&lt;p&gt;There are also complications as components now have a &lt;em&gt;virtualized&lt;/em&gt; or computed state. Another fact is that child components can have the state before the parent does. To do the immediate event listeners addition without state there needs to be markers in the markup as where elements are. Prism does this with a combination of classes added at build time and custom elements. Using these markers alleviates the need to &amp;quot;render&amp;quot; the whole application.&lt;/p&gt;
&lt;p&gt;There are also complexities around values that are not represented literally in the DOM. For example, the &lt;code&gt;href&lt;/code&gt; on the link tags is interpreted as &lt;code&gt;/i/${id}&lt;/code&gt;. Prism has a limited expression reversal and here creates a &lt;code&gt;slice&lt;/code&gt; expression to get the &lt;code&gt;id&lt;/code&gt; value. But for more complex expressions it breaks down, especially for not 1:1 expressions where it is impossible.&lt;/p&gt;
&lt;p&gt;So yeah, this is super early and experimental stuff. If you have any questions or feedback it would be great to leave them in the comments.&lt;/p&gt;
&lt;p&gt;You can follow me and the development of Prism &lt;a href=&quot;https://twitter.com/kaleidawave&quot;&gt;@kaleidawave&lt;/a&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Hacker News Clone with Prism &amp; Rust</title>
    <link href="https://kaleidawave.github.io/posts/hackernews-clone-prism-rust/"/>
    <updated>2020-11-10T00:00:00Z</updated>
    <id>https://kaleidawave.github.io/posts/hackernews-clone-prism-rust/</id>
    <summary>Building a universally rendered Hacker News Clone using Prism, Rust and Actix-Web</summary>
    <content xml:lang="en" type="html">&lt;p&gt;Last week I recreated the &lt;a href=&quot;https://news.ycombinator.com/news&quot;&gt;Hacker News site&lt;/a&gt;. It is built as an isomorphic site with a Prism compiled frontend and a Rust backend. In this post, I will illustrate some of the benefits that using &lt;a href=&quot;https://github.com/kaleidawave/prism&quot;&gt;Prism compiler&lt;/a&gt; has on this site.&lt;/p&gt;
&lt;h3 id=&quot;rust&quot; tabindex=&quot;-1&quot;&gt;Isomorphic sites with a Rust backend&lt;/h3&gt;
&lt;p&gt;Currently, most sites are client-side rendered apps built with a framework. client-side frameworks make development easier by using a more declarative programming style. Using the client runtime can add more reactive interactions without going back to the network. client-side frameworks make SPA&#39;s easier to develop.&lt;/p&gt;
&lt;p&gt;However, a pure client-side site lacks fast start-up times. Before any content is added to the DOM JavaScript must be downloaded, parsed and executed. This relies on the network speed and speed of the client device. There is also the problem that if this process fails then you end up with a white page without any content. Another problem is that each request returns the same empty HTML so there are problems with search engine indexing and link metadata previews between different pages if the bots don&#39;t evaluate the JS.&lt;/p&gt;
&lt;p&gt;Client-side rendering is acceptable for mostly interactive sites (e.g. &lt;a href=&quot;https://www.figma.com/&quot;&gt;Figma&lt;/a&gt;) but does not suit more contentful sites where content is more important than reactivity.&lt;/p&gt;
&lt;p&gt;So instead of a server do server-side rendering (SSR) to generate the initial page. SSR fixes the above problems as there is no reliance on the client runtime for generating content. SSR responses contain relevant non-unique markup so search engine indexers and link metadata bots can work without them running JS.&lt;/p&gt;
&lt;p&gt;This is true for the &lt;a href=&quot;https://news.ycombinator.com/news&quot;&gt;Hacker News site&lt;/a&gt; that renders pages on the server, which is a good architecture as reading posts and comments is more important than interactions.&lt;/p&gt;
&lt;p&gt;Server-side rendering client-side code is already being down within frameworks. &lt;a href=&quot;https://www.npmjs.com/package/react-dom&quot;&gt;react-server/dom&lt;/a&gt; has &lt;code&gt;renderToString&lt;/code&gt;, and &lt;a href=&quot;https://svelte.dev/docs#Server-side_component_API&quot;&gt;Svelte components have a similar method&lt;/a&gt;. Then there are isomorphic frameworks like &lt;a href=&quot;https://github.com/vercel/next.js&quot;&gt;Nextjs&lt;/a&gt; and &lt;a href=&quot;https://github.com/sveltejs/sapper&quot;&gt;sapper&lt;/a&gt; which tie this all in together.&lt;/p&gt;
&lt;h3 class=&quot;center&quot;&gt;&lt;p&gt;However the above methods require a JavaScript runtime&lt;/p&gt;
&lt;/h3&gt;
&lt;p&gt;So in my own framework, I experimented with the feature to compile views to Rust functions. All &lt;code&gt;.prism&lt;/code&gt; components are compiled to native Rust string concatenation functions. This has many benefits:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Single source, no need to rewrite for different server languages&lt;/li&gt;
&lt;li&gt;Changes to &lt;code&gt;.prism&lt;/code&gt; components are reflected and kept inline with the Rust methods&lt;/li&gt;
&lt;li&gt;client-side markup and server-side markup are kept in sync preventing issues when making components interactive&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It also compiles across the &lt;code&gt;interface&lt;/code&gt; definitions to Rust&#39;s &lt;code&gt;struct&lt;/code&gt; definitions, which retains the strong type safety. The Rust compiler will pick up any other issues with the outputted Rust functions. This is a step above &lt;a href=&quot;https://handlebarsjs.com/&quot;&gt;handlebars&lt;/a&gt; where type errors are left to runtime.&lt;/p&gt;
&lt;p&gt;It is not as complete as Nextjs which builds the whole backend for you. Prism only builds out functions which then must be connected up. But I prefer this design as getting data on the server and the client is very different (not for this example but for applications where you have full control over the stack). Prism is not a full-stack framework as while it exposes the render methods in Rust modules, it doesn&#39;t generate the routing needed in Rust.&lt;/p&gt;
&lt;p&gt;Prism hackernews uses actix-web under the hood which is in the &lt;a href=&quot;https://www.techempower.com/benchmarks/#section=data-r19&quot;&gt;top 5 fastest backend frameworks in the tech empower benchmarks&lt;/a&gt;, of that list raw NodeJS server places 152nd. According to the benchmark it makes actix-web 7x faster than a raw NodeJS server.&lt;/p&gt;
&lt;p&gt;For this example it doesn&#39;t really make much of a difference as the biggest time here is making HTTP requests to the &lt;a href=&quot;https://github.com/HackerNews/API&quot;&gt;HN API&lt;/a&gt;. A single request to the homepage takes 11 http requests with a lot of them being chained.&lt;/p&gt;
&lt;p&gt;Aside from the speed improvements it also means that if you have written your REST API in Rust then you can add SSR to your site reusing the same server and logic rather than having to rewrite server-side data fetching in a new NodeJS server.&lt;/p&gt;
&lt;p&gt;It is already possible to server render SPAs in other languages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Through calling directly to v8 API. However, this has a bit of overhead and isn&#39;t as fast as compiling to native. It loses strong typing and can be complex to integrate.&lt;/li&gt;
&lt;li&gt;Rewriting the client view code in a templating engine supported in the language. As well as taking a lot of work initially, it is difficult to maintain the client code with changes to the server-side templates. Mismatches can lead to issues when the frontend logic gets a different response than what the client-side was expecting.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;jit-hydration&quot; tabindex=&quot;-1&quot;&gt;JIT hydration&lt;/h3&gt;
&lt;p&gt;When building isomorphic sites it often makes the frontend more confusing. Now the frontend it is not the start of the world and there is existing markup. The biggest issue from this is recreating the state that was on the server now on the front-end. With both server and client-rendered DOM the view is the same but the JS state is not there on server responses. Getting the state in JS by doing a data fetch is not good as it may be out of sync with the server content. So the approach used by most SSR frameworks is to send down a JSON or JS blob in a script tag that contains the JS object used to generate the markup response.&lt;/p&gt;
&lt;p&gt;This is a common practice and can be seen on nytimes where (at the time of this being written) ~75% of the home page response is the state loaded into the &lt;code&gt;window.__preloadedData&lt;/code&gt; variable:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kaleidawave.github.io/media/demos/new_york_times_preload_data.png&quot; alt=&quot;lots of JSON&quot; /&gt;&lt;/p&gt;
&lt;p&gt;There are a few issues with this approach:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Some of the object is not used. Some implementations use &lt;code&gt;Proxy&lt;/code&gt;s to identify unused &amp;quot;leaves&amp;quot; but this is complex and expensive to do.&lt;/li&gt;
&lt;li&gt;Most of the data is already sent down in the markup.&lt;/li&gt;
&lt;li&gt;JSON cannot represent types other than &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;number&lt;/code&gt;, &lt;code&gt;boolean&lt;/code&gt;, &lt;code&gt;object&lt;/code&gt; and &lt;code&gt;Array&lt;/code&gt;. No &lt;code&gt;Date&lt;/code&gt; :(&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Prism&#39;s approach ditches any sort of JSON or JS blob and the server response only sends markup:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;!&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;DOCTYPE&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;html&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;html&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;lang&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;en&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;head&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;module&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;src&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;/bundle.1w99.js&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;link&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;rel&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;stylesheet&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;/bundle.lxt.css&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;Hacker News&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;meta&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;description&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;content&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;Prism &amp;amp; Rust based HN clone&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;head&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;router-component&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;main-layout&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;data-ssr&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;header&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;header&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;p900&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;index-page&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;data-ssr&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;ol&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;pwf4&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;story-preview&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;data-ssr&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;buttons&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;p1lb2&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;disabled&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;amp;#9650;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;plwi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;disabled&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;amp;#9660;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;pavi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;p1kxi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;...&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                            Fire declared in OVH SBG2 datacentre building&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;pxwh&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;660&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;&amp;lt;!----&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; points | by&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;p1ztd&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;...&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                            &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;&amp;lt;!----&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;finniananderson&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;&amp;lt;!----&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; | &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;pos3&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;...&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                            304&lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;&amp;lt;!----&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; comments&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                                &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                            &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;story-preview&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;ol&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;index-page&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;footer&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;footer&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;main-layout&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;router-component&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;html&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;!&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;DOCTYPE&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;html&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;html&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;lang&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;en&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;head&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;module&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;src&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;/bundle.1w99.js&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;link&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;rel&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;stylesheet&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;/bundle.lxt.css&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;Hacker News&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;title&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;meta&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;description&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;content&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;Prism &amp;amp; Rust based HN clone&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;head&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;router-component&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;main-layout&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;data-ssr&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;header&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;header&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;p900&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;index-page&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;data-ssr&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;ol&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;pwf4&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;story-preview&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;data-ssr&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;buttons&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;p1lb2&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;disabled&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;amp;#9650;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;plwi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;disabled&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;amp;#9660;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;button&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;pavi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;p1kxi&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;...&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                            Fire declared in OVH SBG2 datacentre building&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;h2&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;pxwh&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;660&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;&amp;lt;!----&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; points | by&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;p1ztd&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;...&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                            &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;&amp;lt;!----&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;finniananderson&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;&amp;lt;!----&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; | &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;pos3&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;href&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;...&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                            304&lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;&amp;lt;!----&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; comments&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                                &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                            &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;story-preview&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;ol&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;index-page&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;footer&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;footer&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;main-layout&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;router-component&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;html&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But can still get the state of the application at runtime:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;JSON&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;stringify&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(document.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;index-page&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;).data)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;JSON&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;stringify&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(document.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;querySelector&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;index-page&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;).data)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;quot;stories&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;quot;url&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;http://travaux.ovh.net/?do=details&amp;amp;id=49471&amp;amp;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;quot;title&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;Fire declared in OVH SBG2 datacentre building&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;quot;score&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;660&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;quot;by&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;finniananderson&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;quot;id&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;26407323&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;&amp;quot;descendants&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;304&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA198; font-style: italic&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    ]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;quot;stories&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;quot;url&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;http://travaux.ovh.net/?do=details&amp;amp;id=49471&amp;amp;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;quot;title&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;Fire declared in OVH SBG2 datacentre building&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;quot;score&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;660&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;quot;by&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;finniananderson&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;quot;id&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;26407323&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;&amp;quot;descendants&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;304&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #82071E; font-style: italic&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    ]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So how does it do this?&lt;/p&gt;
&lt;p&gt;As Prism is a compiler, it knows the bindings at build time. With the knowledge of bindings, Prism can compile in getters for each property that accesses the DOM. Once values are retrieved from the DOM they are cached in the component state and will act the same way as if the data was instantiated on the client.&lt;/p&gt;
&lt;p&gt;The runtime does this in quite a special way to be efficient. Getting the data is only done once that member is evaluated, rather when the document or component loads. If you evaluate &lt;code&gt;temp1.data.stories[2].title&lt;/code&gt; it will only load in the 3rd story, and from the story only the title property rather than bringing in every story and constructing the whole state (not that the getting the state from the HTML is expensive, in practice getting the whole state via JSON took 6ms. But in applications with more than 10 stories on the home page the improvement is visible).&lt;/p&gt;
&lt;p&gt;Some of the advantages of JIT hydration:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Smaller HTML payload sizes.&lt;/li&gt;
&lt;li&gt;Simplicity, all a component needs to have data is SSR DOM content.&lt;/li&gt;
&lt;li&gt;Complications for objects that cannot be represented in JSON (DateTime 👀).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Although values in the DOM are all strings, Prism converts the string to the correct types. This can be seen from the &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;score&lt;/code&gt; value on each story in the state.&lt;/p&gt;
&lt;p&gt;Recreating the state from the rendered markup is not a new thing. Many existing SSR sites manually write JS in the runtime script to get values. The actual HN site does this in its vote logic to where it pulls in the story identifer from the elements identifer:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;vote&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;el&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;how&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; id &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; el.id.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;split&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;/_/&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)[&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; up &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;up_&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; id);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;vis&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(up, how &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;#39;un&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;vote&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;el&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;how&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; id &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; el.id.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;split&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;/_/&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)[&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;var&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; up &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;up_&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; id);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;vis&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(up, how &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;#39;un&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But Prism automates this process for a declarative input. In contrast to the about logic in &lt;code&gt;hn.js&lt;/code&gt;, which is handwritten and relies on the fact that the server-rendered element&#39;s id includes the id of the post.&lt;/p&gt;
&lt;h3 id=&quot;bundle-size&quot; tabindex=&quot;-1&quot;&gt;Bundle size&lt;/h3&gt;
&lt;p&gt;The JS bundle for hacker news is 12.6kb uncompressed (3.5kb Gzip or 3.2kb Brotli). This includes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;All the render logic for the pages&lt;/li&gt;
&lt;li&gt;All the reactivity&lt;/li&gt;
&lt;li&gt;A single-page router&lt;/li&gt;
&lt;li&gt;All the client data fetching logic&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Actual HN runs on ~4kb of uncompressed JS but then it is not a spa or framework built so I don&#39;t think there is any comparison with it. On the other hand, the Svelte HN implementation runs on 30kb of JS (although it doesn&#39;t seem to be minified). But when it comes to these small numbers it doesn&#39;t matter, as long as it&#39;s under 50kb of JS it&#39;s pretty responsive.&lt;/p&gt;
&lt;p&gt;Coming back to the size, with any abstraction or automated approach there is bound to be more JS outputted than writing it out by hand. Prism automates a lot of stuff, and provides the declarative approach that exists in all other client-side frameworks while keeping the bundle size very low:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;div class=&quot;shiki-container&quot;&gt;&lt;pre class=&quot;shiki shiki-dark&quot; style=&quot;background-color: #0d1117&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;#html&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;by&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;by {by}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;sub-comments&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;#for&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;const subComment of subComments&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA198; font-style: italic&quot;&gt;This&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;$data&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;&amp;quot;subComment&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #FFA198; font-style: italic&quot;&gt;This&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #8B949E&quot;&gt;// @useRustStatement #[derive(Clone, Debug, serde::Deserialize)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;IComment&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;by&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        @&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;useRustStatement&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`#[serde(default)]`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        @&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;useRustStatement&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`#[serde(default)]`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;subComments&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;IComment&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        @&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;useRustStatement&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`#[serde(default)]`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;kids&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;maxCommentDepth&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;Comment&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Component&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;IComment&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getComment&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;depth&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;endpoint&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`https://hacker-news.firebaseio.com/v0/item/${&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;}.json`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;request&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(endpoint);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;comment&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; request.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;json&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;comment) &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;throw&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Error&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;`Could not find comment under id ${&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #A5D6FF&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; (comment.kids &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; depth &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; maxCommentDepth) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;subComments&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; comment.kids&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    .&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;slice&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                    .&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FFA657&quot;&gt;kidID&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; Comment.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;getComment&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(kidID, depth &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                comment.subComments &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;Promise&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #D2A8FF&quot;&gt;all&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;(subComments);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            } &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;                comment.subComments &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; [];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; comment;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;style&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &amp;amp; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;display&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;margin&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;font-size&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;14&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;.by&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;display&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;margin-top&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;font-style&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;italic&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;font-size&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;.sub-comments&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;padding-left&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #79C0FF&quot;&gt;24&lt;/span&gt;&lt;span style=&quot;color: #FF7B72&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #7EE787&quot;&gt;style&lt;/span&gt;&lt;span style=&quot;color: #C9D1D9&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;shiki shiki-light&quot; style=&quot;background-color: #ffffff&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;#html&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;by&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;by {by}&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;sub-comments&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;#for&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;const subComment of subComments&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #82071E; font-style: italic&quot;&gt;This&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;$data&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;&amp;quot;subComment&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #82071E; font-style: italic&quot;&gt;This&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;li&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;template&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #6E7781&quot;&gt;// @useRustStatement #[derive(Clone, Debug, serde::Deserialize)]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;interface&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;IComment&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;by&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        @&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;useRustStatement&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`#[serde(default)]`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        @&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;useRustStatement&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`#[serde(default)]`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;subComments&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;IComment&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        @&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;useRustStatement&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`#[serde(default)]`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;kids&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Array&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;maxCommentDepth&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;export&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;Comment&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Component&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;IComment&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getComment&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;number&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;depth&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;endpoint&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`https://hacker-news.firebaseio.com/v0/item/${&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;}.json`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;request&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;fetch&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(endpoint);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;comment&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; request.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;json&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;comment) &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;throw&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Error&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;`Could not find comment under id ${&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #0A3069&quot;&gt;}`&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; (comment.kids &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; depth &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; maxCommentDepth) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;subComments&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; comment.kids&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    .&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;slice&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                    .&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #953800&quot;&gt;kidID&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; Comment.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;getComment&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(kidID, depth &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                comment.subComments &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;Promise&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8250DF&quot;&gt;all&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;(subComments);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            } &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;                comment.subComments &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; [];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; comment;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;script&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;style&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &amp;amp; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;display&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;margin&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;div&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;font-size&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;14&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;span&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;.by&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;display&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;margin-top&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;font-style&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;italic&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;font-size&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;ul&lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;.sub-comments&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;padding-left&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: #0550AE&quot;&gt;24&lt;/span&gt;&lt;span style=&quot;color: #CF222E&quot;&gt;px&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: #116329&quot;&gt;style&lt;/span&gt;&lt;span style=&quot;color: #24292F&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When Prism&#39;s HN app launches, the custom elements connected events fire and add event listeners to the existing markup. Here the upvote and downvote buttons on the story preview are connected as event listeners. Prism recognizes that the server is not the client and all elements with events will be server-rendered with the disable attribute (which is removed once the listener is added).&lt;/p&gt;
&lt;p&gt;When the button is clicked, the upvote method will fire and inside it will increment &lt;code&gt;this.data.score&lt;/code&gt;. If the value is not already in the data cache it will be hydrated in. The increment operator will then fire a set which under the hood fires an imperative DOM call to update the view and the view will now show &lt;code&gt;score + 1&lt;/code&gt; points.&lt;/p&gt;
&lt;p&gt;Prism also has a built-in static router. Clicking on the comments anchor tag will route to the story&#39;s page. This is just a regular anchor tag under the hood so if the JS fails it will do a regular redirect and hit the server.&lt;/p&gt;
&lt;p&gt;SPA routing has the benefits over the MPA that HN has. On a redirect, it only has to load the data for that new view in and not the whole markup. This can reduce the payload. On redirecting the HN header is retained in the DOM and only the page is switched out. Not used here but also animations can be done rather than a flash of content. It also means that this site works without SSR and can be cached in a service worker.&lt;/p&gt;
&lt;hr /&gt;
&lt;blockquote&gt;
&lt;p&gt;This is only experimental at the moment, there is a lot of stuff hacked together in the compiler to get this example to work. The compilation is shaky at best and only works for simple examples such as this. This is not a drop in replacement for a nextjs site. And lacks a lot of the reactivity that React, Vue and Svelte have to offer.&lt;/p&gt;
&lt;p&gt;For now this is a proposal and a experiment to see whether there are improvements that can be made in this.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;future&quot; tabindex=&quot;-1&quot;&gt;Future&lt;/h3&gt;
&lt;p&gt;One improvement that would improve page response times is streaming the document to the client. Currently, the server-rendered page is only sent to the client once the whole server response has been built. Using streaming, the client here would get the header to render in before the backend has even hit the HN API. With each backend request the response could be immediately sent to the client to be rendered in. This would also work really well with the JIT hydration.&lt;/p&gt;
&lt;p&gt;With the addition of Rust to the target outputs for Prism it proves that there is the ability to construct SSR functions for other languages. The addition took less than 2 weeks to implement and a lot of that was opening up the pipeline to be less language-oriented (and a lot of wrangling with Rust&#39;s memory safety model). There is an opportunity to add support for more languages if this is a beneficial feature but I think the Rust implementation needs to be scrutinized and tightened up before that happens.&lt;/p&gt;
&lt;p&gt;This clone is also missing many features from the actual version that I would still like to implement. But I only spun this example up in a week and before then I had no experience with Rust. Also during development Prism was missing a few features such as recursive components (used for the comments) and unsafe html (HN text field includes raw HTML) so I added them for version 1.3.0.&lt;/p&gt;
&lt;p&gt;For now, you can clone the clone and try it out here: &lt;a href=&quot;https://github.com/kaleidawave/hackernews-prism&quot;&gt;kaleidawave/hackernews-prism&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For a JS-based isomorphic site, there is &lt;a href=&quot;https://github.com/kaleidawave/prism-ssr-demo&quot;&gt;kaleidawave/prism-ssr-demo&lt;/a&gt; and can be run on &lt;a href=&quot;https://repl.it/github/kaleidawave/prism-ssr-demo&quot;&gt;replit&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
</feed>