Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gibbok committed Jun 2, 2024
1 parent 79d5070 commit 0bc8c93
Show file tree
Hide file tree
Showing 31 changed files with 43 additions and 7 deletions.
12 changes: 10 additions & 2 deletions book/others/index.html

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions book/table-of-contents/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
<li>Lowercase&#x3C;T></li>
<li>Capitalize&#x3C;T></li>
<li>Uncapitalize&#x3C;T></li>
<li>NoInfer&#x3C;T></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -295,6 +296,7 @@
<li>await using declaration</li>
</ul>
</li>
<li>Import Attributes</li>
</ul>
</li>
</ul>
Expand Down
10 changes: 9 additions & 1 deletion book/type-manipulation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,12 @@ <h4 id="capitalizet">Capitalize&#x3C;T></h4>
<div class="expressive-code"><figure class="frame not-content"><figcaption class="header"></figcaption><pre tabindex="0"><code><div class="ec-line"><span style="--0:#C792EA;--1:#8844AE">type</span><span style="--0:#D6DEEB;--1:#403F53"> MyType </span><span style="--0:#C792EA;--1:#8844AE">=</span><span style="--0:#D6DEEB;--1:#403F53"> </span><span style="--0:#FFCB8B;--1:#111111">Capitalize</span><span style="--0:#D6DEEB;--1:#403F53">&#x3C;</span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#ECC48D;--1:#984E4D">abc</span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#D6DEEB;--1:#403F53">>; </span><span style="--0:#919F9F;--1:#5D6376">// "Abc"</span></div></code></pre><div class="copy"><button title="Copy to clipboard" data-copied="Copied!" data-code="type MyType = Capitalize<&#x27;abc&#x27;>; // &#x22;Abc&#x22;"><div></div></button></div></figure></div>
<h4 id="uncapitalizet">Uncapitalize&#x3C;T></h4>
<p>Uncapitalize the name of the input type T.</p>
<div class="expressive-code"><figure class="frame not-content"><figcaption class="header"></figcaption><pre tabindex="0"><code><div class="ec-line"><span style="--0:#C792EA;--1:#8844AE">type</span><span style="--0:#D6DEEB;--1:#403F53"> MyType </span><span style="--0:#C792EA;--1:#8844AE">=</span><span style="--0:#D6DEEB;--1:#403F53"> </span><span style="--0:#FFCB8B;--1:#111111">Uncapitalize</span><span style="--0:#D6DEEB;--1:#403F53">&#x3C;</span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#ECC48D;--1:#984E4D">Abc</span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#D6DEEB;--1:#403F53">>; </span><span style="--0:#919F9F;--1:#5D6376">// "abc"</span></div></code></pre><div class="copy"><button title="Copy to clipboard" data-copied="Copied!" data-code="type MyType = Uncapitalize<&#x27;Abc&#x27;>; // &#x22;abc&#x22;"><div></div></button></div></figure></div> </div> <footer class="astro-3yyafb3n"> <div class="meta sl-flex astro-3yyafb3n"> </div> <div class="pagination-links astro-u2l5gyhi" dir="ltr"> <a href="/typescript-book/book/triple-slash-directives/" rel="prev" class="astro-u2l5gyhi"> <svg aria-hidden="true" class="astro-u2l5gyhi astro-c6vsoqas" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17 11H9.41l3.3-3.29a1.004 1.004 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33 1 1 0 0 0 0 .76 1 1 0 0 0 .21.33l5 5a1.002 1.002 0 0 0 1.639-.325 1 1 0 0 0-.219-1.095L9.41 13H17a1 1 0 0 0 0-2Z"/></svg> <span class="astro-u2l5gyhi"> Previous <br class="astro-u2l5gyhi"> <span class="link-title astro-u2l5gyhi">59. Triple-Slash Directives</span> </span> </a> <a href="/typescript-book/book/others/" rel="next" class="astro-u2l5gyhi"> <svg aria-hidden="true" class="astro-u2l5gyhi astro-c6vsoqas" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17.92 11.62a1.001 1.001 0 0 0-.21-.33l-5-5a1.003 1.003 0 1 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1.002 1.002 0 0 0 .325 1.639 1 1 0 0 0 1.095-.219l5-5a1 1 0 0 0 .21-.33 1 1 0 0 0 0-.76Z"/></svg> <span class="astro-u2l5gyhi"> Next <br class="astro-u2l5gyhi"> <span class="link-title astro-u2l5gyhi">61. Others</span> </span> </a> </div> </footer> </div> </div> </main> </div> </div> </div> </div> </body></html>
<div class="expressive-code"><figure class="frame not-content"><figcaption class="header"></figcaption><pre tabindex="0"><code><div class="ec-line"><span style="--0:#C792EA;--1:#8844AE">type</span><span style="--0:#D6DEEB;--1:#403F53"> MyType </span><span style="--0:#C792EA;--1:#8844AE">=</span><span style="--0:#D6DEEB;--1:#403F53"> </span><span style="--0:#FFCB8B;--1:#111111">Uncapitalize</span><span style="--0:#D6DEEB;--1:#403F53">&#x3C;</span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#ECC48D;--1:#984E4D">Abc</span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#D6DEEB;--1:#403F53">>; </span><span style="--0:#919F9F;--1:#5D6376">// "abc"</span></div></code></pre><div class="copy"><button title="Copy to clipboard" data-copied="Copied!" data-code="type MyType = Uncapitalize<&#x27;Abc&#x27;>; // &#x22;abc&#x22;"><div></div></button></div></figure></div>
<h4 id="noinfert">NoInfer&#x3C;T></h4>
<p>NoInfer is a utility type designed to block the automatic inference of types within the scope of a generic function.</p>
<p>Example:</p>
<div class="expressive-code"><figure class="frame not-content"><figcaption class="header"></figcaption><pre tabindex="0"><code><div class="ec-line"><span style="--0:#919F9F;--1:#5D6376">// Automatic inference of types within the scope of a generic function.</span></div><div class="ec-line"><span style="--0:#C792EA;--1:#8844AE">function</span><span style="--0:#D6DEEB;--1:#403F53"> </span><span style="--0:#82AAFF;--1:#3B61B0">fn</span><span style="--0:#D6DEEB;--1:#403F53">&#x3C;</span><span style="--0:#FFCB8B;--1:#111111">T</span><span style="--0:#D6DEEB;--1:#403F53"> </span><span style="--0:#C792EA;--1:#8844AE">extends</span><span style="--0:#D6DEEB;--1:#403F53"> </span><span style="--0:#C5E478;--1:#3B61B0">string</span><span style="--0:#D6DEEB;--1:#403F53">></span><span style="--0:#D9F5DD;--1:#111111">(</span><span style="--0:#D7DBE0;--1:#403F53">x</span><span style="--0:#7FDBCA;--1:#096E72">:</span><span style="--0:#D6DEEB;--1:#403F53"> </span><span style="--0:#FFCB8B;--1:#111111">T</span><span style="--1:#403F53"><span style="--0:#D6DEEB">[], </span><span style="--0:#D7DBE0">y</span></span><span style="--0:#7FDBCA;--1:#096E72">:</span><span style="--0:#D6DEEB;--1:#403F53"> </span><span style="--1:#111111"><span style="--0:#FFCB8B">T</span><span style="--0:#D9F5DD">)</span></span><span style="--0:#D6DEEB;--1:#403F53"> {</span></div><div class="ec-line"><span style="--0:#D6DEEB;--1:#403F53"> </span><span style="--0:#C792EA;--1:#8844AE">return</span><span style="--0:#D6DEEB;--1:#403F53"> x</span><span style="--0:#C792EA;--1:#8844AE">.</span><span style="--0:#82AAFF;--1:#3B61B0">concat</span><span style="--0:#D6DEEB;--1:#403F53">(y);</span></div><div class="ec-line"><span style="--0:#D6DEEB;--1:#403F53">}</span></div><div class="ec-line"><span style="--0:#C792EA;--1:#8844AE">const </span><span style="--0:#82AAFF;--1:#3B61B0">r</span><span style="--0:#C792EA;--1:#8844AE"> = </span><span style="--0:#82AAFF;--1:#3B61B0">fn</span><span style="--0:#D6DEEB;--1:#403F53">([</span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#ECC48D;--1:#984E4D">a</span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#D6DEEB;--1:#403F53">, </span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#ECC48D;--1:#984E4D">b</span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#D6DEEB;--1:#403F53">]</span><span style="--0:#C792EA;--1:#8844AE">, </span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#ECC48D;--1:#984E4D">c</span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#D6DEEB;--1:#403F53">); </span><span style="--0:#919F9F;--1:#5D6376">// Type here is ("a" | "b" | "c")[]</span></div></code></pre><div class="copy"><button title="Copy to clipboard" data-copied="Copied!" data-code="// Automatic inference of types within the scope of a generic function.function fn<T extends string>(x: T[], y: T) { return x.concat(y);}const r = fn([&#x27;a&#x27;, &#x27;b&#x27;], &#x27;c&#x27;); // Type here is (&#x22;a&#x22; | &#x22;b&#x22; | &#x22;c&#x22;)[]"><div></div></button></div></figure></div>
<p>With NoInfer:</p>
<!-- skip -->
<div class="expressive-code"><figure class="frame not-content"><figcaption class="header"></figcaption><pre tabindex="0"><code><div class="ec-line"><span style="--0:#919F9F;--1:#5D6376">// Example function that uses NoInfer to prevent type inference</span></div><div class="ec-line"><span style="--0:#C792EA;--1:#8844AE">function</span><span style="--0:#D6DEEB;--1:#403F53"> </span><span style="--0:#82AAFF;--1:#3B61B0">fn2</span><span style="--0:#D6DEEB;--1:#403F53">&#x3C;</span><span style="--0:#FFCB8B;--1:#111111">T</span><span style="--0:#D6DEEB;--1:#403F53"> </span><span style="--0:#C792EA;--1:#8844AE">extends</span><span style="--0:#D6DEEB;--1:#403F53"> </span><span style="--0:#C5E478;--1:#3B61B0">string</span><span style="--0:#D6DEEB;--1:#403F53">></span><span style="--0:#D9F5DD;--1:#111111">(</span><span style="--0:#D7DBE0;--1:#403F53">x</span><span style="--0:#7FDBCA;--1:#096E72">:</span><span style="--0:#D6DEEB;--1:#403F53"> </span><span style="--0:#FFCB8B;--1:#111111">T</span><span style="--1:#403F53"><span style="--0:#D6DEEB">[], </span><span style="--0:#D7DBE0">y</span></span><span style="--0:#7FDBCA;--1:#096E72">:</span><span style="--0:#D6DEEB;--1:#403F53"> </span><span style="--0:#FFCB8B;--1:#111111">NoInfer</span><span style="--0:#D6DEEB;--1:#403F53">&#x3C;</span><span style="--0:#FFCB8B;--1:#111111">T</span><span style="--0:#D6DEEB;--1:#403F53">></span><span style="--0:#D9F5DD;--1:#111111">)</span><span style="--0:#D6DEEB;--1:#403F53"> {</span></div><div class="ec-line"><span style="--0:#D6DEEB;--1:#403F53"> </span><span style="--0:#C792EA;--1:#8844AE">return</span><span style="--0:#D6DEEB;--1:#403F53"> x</span><span style="--0:#C792EA;--1:#8844AE">.</span><span style="--0:#82AAFF;--1:#3B61B0">concat</span><span style="--0:#D6DEEB;--1:#403F53">(y);</span></div><div class="ec-line"><span style="--0:#D6DEEB;--1:#403F53">}</span></div><div class="ec-line">
</div><div class="ec-line"><span style="--0:#C792EA;--1:#8844AE">const </span><span style="--0:#82AAFF;--1:#3B61B0">r2</span><span style="--0:#C792EA;--1:#8844AE"> = </span><span style="--0:#82AAFF;--1:#3B61B0">fn2</span><span style="--0:#D6DEEB;--1:#403F53">([</span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#ECC48D;--1:#984E4D">a</span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#D6DEEB;--1:#403F53">, </span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#ECC48D;--1:#984E4D">b</span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#D6DEEB;--1:#403F53">]</span><span style="--0:#C792EA;--1:#8844AE">, </span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#ECC48D;--1:#984E4D">c</span><span style="--0:#D9F5DD;--1:#111111">'</span><span style="--0:#D6DEEB;--1:#403F53">); </span><span style="--0:#919F9F;--1:#5D6376">// Error: Type Argument of type '"c"' is not assignable to parameter of type '"a" | "b"'.</span></div></code></pre><div class="copy"><button title="Copy to clipboard" data-copied="Copied!" data-code="// Example function that uses NoInfer to prevent type inferencefunction fn2<T extends string>(x: T[], y: NoInfer<T>) { return x.concat(y);}const r2 = fn2([&#x27;a&#x27;, &#x27;b&#x27;], &#x27;c&#x27;); // Error: Type Argument of type &#x27;&#x22;c&#x22;&#x27; is not assignable to parameter of type &#x27;&#x22;a&#x22; | &#x22;b&#x22;&#x27;."><div></div></button></div></figure></div> </div> <footer class="astro-3yyafb3n"> <div class="meta sl-flex astro-3yyafb3n"> </div> <div class="pagination-links astro-u2l5gyhi" dir="ltr"> <a href="/typescript-book/book/triple-slash-directives/" rel="prev" class="astro-u2l5gyhi"> <svg aria-hidden="true" class="astro-u2l5gyhi astro-c6vsoqas" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17 11H9.41l3.3-3.29a1.004 1.004 0 1 0-1.42-1.42l-5 5a1 1 0 0 0-.21.33 1 1 0 0 0 0 .76 1 1 0 0 0 .21.33l5 5a1.002 1.002 0 0 0 1.639-.325 1 1 0 0 0-.219-1.095L9.41 13H17a1 1 0 0 0 0-2Z"/></svg> <span class="astro-u2l5gyhi"> Previous <br class="astro-u2l5gyhi"> <span class="link-title astro-u2l5gyhi">59. Triple-Slash Directives</span> </span> </a> <a href="/typescript-book/book/others/" rel="next" class="astro-u2l5gyhi"> <svg aria-hidden="true" class="astro-u2l5gyhi astro-c6vsoqas" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.5rem;"><path d="M17.92 11.62a1.001 1.001 0 0 0-.21-.33l-5-5a1.003 1.003 0 1 0-1.42 1.42l3.3 3.29H7a1 1 0 0 0 0 2h7.59l-3.3 3.29a1.002 1.002 0 0 0 .325 1.639 1 1 0 0 0 1.095-.219l5-5a1 1 0 0 0 .21-.33 1 1 0 0 0 0-.76Z"/></svg> <span class="astro-u2l5gyhi"> Next <br class="astro-u2l5gyhi"> <span class="link-title astro-u2l5gyhi">61. Others</span> </span> </a> </div> </footer> </div> </div> </main> </div> </div> </div> </div> </body></html>
Binary file removed pagefind/fragment/en_31ffe2a.pf_fragment
Binary file not shown.
Binary file added pagefind/fragment/en_3497ca8.pf_fragment
Binary file not shown.
Binary file added pagefind/fragment/en_62c865e.pf_fragment
Binary file not shown.
Binary file removed pagefind/fragment/en_91f1ef4.pf_fragment
Binary file not shown.
Binary file removed pagefind/fragment/en_a09dbc2.pf_fragment
Binary file not shown.
Binary file added pagefind/fragment/en_d16c3d4.pf_fragment
Binary file not shown.
Binary file removed pagefind/fragment/zh-cn_2832d98.pf_fragment
Binary file not shown.
Binary file added pagefind/fragment/zh-cn_37a442e.pf_fragment
Binary file not shown.
Binary file added pagefind/fragment/zh-cn_6e1ec3f.pf_fragment
Binary file not shown.
Binary file removed pagefind/fragment/zh-cn_8d42d7b.pf_fragment
Binary file not shown.
Binary file removed pagefind/fragment/zh-cn_a4b5bb7.pf_fragment
Binary file not shown.
Binary file added pagefind/fragment/zh-cn_b9232c9.pf_fragment
Binary file not shown.
Binary file removed pagefind/index/en_85cea7d.pf_index
Binary file not shown.
Binary file added pagefind/index/en_b94bf5e.pf_index
Binary file not shown.
Binary file added pagefind/index/en_c63af47.pf_index
Binary file not shown.
Binary file removed pagefind/index/en_f84f333.pf_index
Binary file not shown.
Binary file removed pagefind/index/zh-cn_4b789fc.pf_index
Binary file not shown.
Binary file added pagefind/index/zh-cn_4f661e5.pf_index
Binary file not shown.
Binary file removed pagefind/index/zh-cn_ef9481d.pf_index
Binary file not shown.
Binary file added pagefind/index/zh-cn_f05362e.pf_index
Binary file not shown.
2 changes: 1 addition & 1 deletion pagefind/pagefind-entry.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"1.0.4","languages":{"zh-cn":{"hash":"zh-cn_9913f963f55d6","wasm":null,"page_count":62},"en":{"hash":"en_e48b7b8e52","wasm":"en","page_count":62}}}
{"version":"1.0.4","languages":{"zh-cn":{"hash":"zh-cn_8ef297bb92887","wasm":null,"page_count":62},"en":{"hash":"en_fd64fa3a81","wasm":"en","page_count":62}}}
Binary file removed pagefind/pagefind.en_e48b7b8e52.pf_meta
Binary file not shown.
Binary file added pagefind/pagefind.en_fd64fa3a81.pf_meta
Binary file not shown.
Binary file added pagefind/pagefind.zh-cn_8ef297bb92887.pf_meta
Binary file not shown.
Binary file removed pagefind/pagefind.zh-cn_9913f963f55d6.pf_meta
Binary file not shown.
12 changes: 10 additions & 2 deletions zh-cn/book/others/index.html

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions zh-cn/book/table-of-contents/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
<li>Lowercase&#x3C;T></li>
<li>Capitalize&#x3C;T></li>
<li>Uncapitalize&#x3C;T></li>
<li>NoInfer&#x3C;T></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -295,6 +296,7 @@
<li>使用声明等待</li>
</ul>
</li>
<li>导入属性</li>
</ul>
</li>
</ul>
Expand Down
Loading

0 comments on commit 0bc8c93

Please sign in to comment.