<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Typescript 邊學邊練

          共 4152字,需瀏覽 9分鐘

           ·

          2021-08-03 08:13

          你是否曾經(jīng):

          1. 看了各種 TS 文檔,寫起來還是似懂非懂;
          2. 接觸了一些 TS 關(guān)鍵字,用起來不太熟練,缺乏明確的理論參考;
          3. TS 寫著寫著降級到了 JS;
          4. 類型在不知道什么地方就斷了層,再也接不上了;

          基于我們踩坑 TS 的過程,總結(jié)了這篇文章。通過邊學邊練,從問題到解答到知識點,帶你體驗類型體操的快樂,并把類型體操應用在日常開發(fā)中。

          • 適合對象:“掌握 JS,看過 TS 的,打算加強理解的前端同學”
          • 看完收獲:“掌握 TS 的若干核心知識點;體會類型體操的快樂”
          • 食用姿勢:
            • 按題不定期食用(每個題都有涉及到相關(guān)知識點)
            • 食用順序:關(guān)鍵詞 -> 題目要求 -> 知識點 -> 解題 -> 答題鏈接 -> 參考答案 -> 參考 JS -> 知識點
            • 場景和解答僅供參考,并不是“TS 完備”的答案

          題目匯總

          序號標題難度指數(shù)關(guān)鍵詞題目摘要
          1.Extract[1]??generics、unionextends從某聯(lián)合類型中選出“和其他類型相交”一部分
          2.Lookup[2]????generics、union、extends從某聯(lián)合類型中選出“滿足特定條件的”一部分
          3.Chainable Option[3]????generics、recursive使用遞歸使類型滿足鏈式調(diào)用
          4.SubType[4]????keyof給對象做 merge 操作
          5.Change Argument[5]??????infer、ReturnType、Parameters操作函數(shù)的參數(shù)和返回值的類型
          6.Underscore[6]??????Template Literal Typesrecursive下劃線字符串轉(zhuǎn)駝峰式
          7.EventEmitter[7]????????generics、function overload、Intersection通過泛型解決函數(shù)參數(shù)間的相互依賴
          8.Permutation[8]????????unionextends、never全排列問題
          9.Simple Vue[9]??????????this模擬一個 Vue 的 this 操作
          10.Union To Tuple[10]??????????function overload、Intersection無序聯(lián)合類型轉(zhuǎn)有序 tuple

          參考鏈接

          1. 類型分發(fā):Documentation - TypeScript 2.8[11]
          2. 泛型:Documentation - Generics[12]
          3. 遞歸類型:Documentation - TypeScript 3.7[13]
          4. 函數(shù)中的泛型:Documentation - More on Functions[14]
          5. keyof 關(guān)鍵字:Documentation - TypeScript 2.1[15]
          6. this 類型:Documentation - Utility Types[16]
          7. infer 關(guān)鍵字:infer | 深入理解 TypeScript[17]
          8. Rest/Spread Parameters:Documentation - TypeScript 3.0[18]
          9. 模板字符串:Documentation - TypeScript 4.1[19]
          10. 字符串部分內(nèi)置類型:Documentation - Template Literal Types[20]
          11. never 判斷:
            • Conditional Types - Checking extends never[21];
            • https://github.com/type-challenges/type-challenges/issues/614
          12. Dependent Type:
            • TypeScript 類型技巧 - 多參數(shù)類型約束[22]
            • Typescript Tips: 動態(tài)重載實現(xiàn)廉價版 dependent type[23]
          13. 關(guān)于交叉類型和函數(shù)重載:
            • TypeScript union function types[24]
          14. 關(guān)于 TS 圖靈完備:證明 JS 和 TS 類型編程是圖靈完備的[25]

          參考資料

          [1]

          Extract: https://juejin.cn/post/6981286316998656008

          [2]

          Lookup: https://juejin.cn/post/6986176614367248392

          [3]

          Chainable Option: https://juejin.cn/post/6986181848116396063

          [4]

          SubType: https://juejin.cn/post/6986606043283324942

          [5]

          Change Argument: https://juejin.cn/post/6987001375938838542

          [6]

          Underscore: https://juejin.cn/post/6987002391212392462

          [7]

          EventEmitter: https://juejin.cn/post/6987585311228297230

          [8]

          Permutation: https://juejin.cn/post/6987586892153765902

          [9]

          Simple Vue: https://juejin.cn/post/6987590161735368718

          [10]

          Union To Tuple: https://juejin.cn/post/6987596107866079269

          [11]

          Documentation - TypeScript 2.8: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types

          [12]

          Documentation - Generics: https://www.typescriptlang.org/docs/handbook/2/generics.html

          [13]

          Documentation - TypeScript 3.7: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#more-recursive-type-aliases

          [14]

          Documentation - More on Functions: https://www.typescriptlang.org/docs/handbook/2/functions.html#generic-functions

          [15]

          Documentation - TypeScript 2.1: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html#keyof-and-lookup-types

          [16]

          Documentation - Utility Types: https://www.typescriptlang.org/docs/handbook/utility-types.html#thistypetype

          [17]

          infer | 深入理解 TypeScript: https://jkchao.github.io/typescript-book-chinese/tips/infer.html#%E4%BB%8B%E7%BB%8D

          [18]

          Documentation - TypeScript 3.0: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html#tuples-in-rest-parameters-and-spread-expressions

          [19]

          Documentation - TypeScript 4.1: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html#template-literal-types

          [20]

          Documentation - Template Literal Types: https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#uppercasestringtype

          [21]

          Conditional Types - Checking extends never: https://github.com/microsoft/TypeScript/issues/23182

          [22]

          TypeScript 類型技巧 - 多參數(shù)類型約束: https://zhuanlan.zhihu.com/p/95828198

          [23]

          Typescript Tips: 動態(tài)重載實現(xiàn)廉價版 dependent type: https://zhuanlan.zhihu.com/p/95829351

          [24]

          TypeScript union function types: https://stackoverflow.com/questions/58629426/typescript-union-function-types

          [25]

          證明 JS 和 TS 類型編程是圖靈完備的: https://juejin.cn/post/6927088564194770951



          第一屆字節(jié)青訓營 - 走進前端「報名啦」??https://mp.weixin.qq.com/s/Pw7Ffi1DNfpYsk00f0gx6w

          瀏覽 55
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  囯产一级持黄视频 | 国产 在线观看 | 超碰大香蕉在线 | 无码无码一区二区三区 | 干AV影院|