
程式碼之外,還有生活的藝術 前端工程師 / 攝影 / 生活紀錄
- 文章298
- 標籤372
標籤查看更多
分類查看更多
- Advanced Web Dev Quiz (27)
- Deep JavaScript Foundations v3 (69)
- Full Stack Fundamentals (47)
- JavaScript Hard Parts v3 (50)
- JS地下城 (5)
- TypeScript Fundamentals (20)
- Web Performance Fundamentals (41)
- You Might Not Need a Framework (32)
- 學習經歷 (2)
- 生活亂談 (2)
- 程式筆記 (3)
最新文章
混合 Dev 和 Life 的所有最新內容
298 篇2026-09-0717 分鐘閱讀
示範用 new 關鍵字寫出 construct signature 描述像 Date 這樣的建構子型別,並用 handleMainEvent 這個處理表單與 iframe 事件的函式,說明函式多載如何用多個函式頭綁定第一個參數與第二個參數的對應關係,避免混搭出不合理的組合,也點出多載頭必須跟底層實作相容的限制。
TypeScript Fundamentals
#frontendMasters #typescriptFundamentals #TypeScript #ConstructSignature #FunctionOverloads #CallSignature 2026-09-0713 分鐘閱讀
用 push 方法實際回傳 number、卻能傳入型別是 void 的回呼參數為例,示範 () => undefined 為何報錯、() => void 卻能通過,說明 void 允許兩個值、跟只有一個成員的 unit type 不同,並釐清 void 當函式回傳型別與當回呼參數型別的語意差異。
TypeScript Fundamentals
#frontendMasters #typescriptFundamentals #TypeScript #VoidType #UnitType #LiteralTypes 2026-09-0614 分鐘閱讀
示範用 interface 的 call signature(冒號)與 type alias 的箭頭語法(=>)替函式定義型別,並討論何時該選 interface、何時該選 type alias:函式庫傾向用可開放擴充的 interface,需要鎖死型別時則用 type alias。
TypeScript Fundamentals
#frontendMasters #typescriptFundamentals #TypeScript #CallSignature #Interface #TypeAlias #OpenInterfaces 2026-09-0616 分鐘閱讀
示範用一個空的 DataTypeRegistry interface 搭配 keyof 與 declare module,讓 book、magazine 模組不改中央檔案就能註冊型別,fetchRecord 的參數因此自動長出 book | magazine,這個模式對函式庫作者開放使用者擴充型別特別有價值。
TypeScript Fundamentals
#frontendMasters #typescriptFundamentals #TypeScript #TypeQueries #Keyof #DeclareModule #OpenInterfaces #NeverType #TypeRegistryPattern 2026-09-0520 分鐘閱讀
keyof 取得物件所有屬性鍵組成的聯集型別,typeof 能從 Promise.all 回傳的複雜 tuple 萃取完整型別(並釐清跟執行期 typeof 的差異,含取得 class 靜態面),加上用方括號索引存取型別特定屬性、可連續串接,並讓聯集索引投射出新的聯集型別,三者合起來能大幅減少重複手寫型別的麻煩。
2026-09-0510 分鐘閱讀
用 number | NestedNumbers[] 這個自我參照的型別別名,示範如何描述可無限往下巢狀的數字陣列結構,說明型別別名處理右側定義的方式跟 JavaScript 運算式求值類似,並澄清現在不需要 interface 搭配 type alias,這種寫法之後會用來定義 JSON 型別。
TypeScript Fundamentals
#frontendMasters #typescriptFundamentals #TypeScript #RecursiveTypes #TypeAlias #UnionTypes 2026-09-0425 分鐘閱讀
示範用 interface 描述物件形狀、用 extends 建立繼承鏈,用 implements 讓 class 遵守 interface 定義的契約,說明為何 interface 只能描述物件形狀,這個限制反而讓它天生跟 implements 相容,比含有聯集型別的 type alias 更適合當類別契約用。
TypeScript Fundamentals
#frontendMasters #typescriptFundamentals #TypeScript #Interface #TypeAlias #Subtyping #HeritageClauses 2026-09-0415 分鐘閱讀
示範型別別名如何把冗長的內嵌物件型別與 tuple 聯集簡化成一個有語意的名字,可以像變數一樣匯入匯出、集中定義一處,編譯後會被完全抹除,並用交集型別做出類似繼承的擴充效果(如替 Date 加上 getDescription 方法),最後點出型別別名能承載任何型別,這點跟 interface 不同。
TypeScript Fundamentals
#frontendMasters #typescriptFundamentals #TypeScript #TypeAlias #IntersectionTypes #UnionTypes #Subtyping 2026-09-0312 分鐘閱讀
延續前一篇聯集型別的 printEven、printLowNumber 等函式範例,改用交集型別(&)重新測試,示範它接受的值範圍極窄,卻能同時滿足多個函式各自的型別要求,並整理聯集與交集在「接受什麼值」與「能保證什麼」上呈現的不對稱關係,最後說明交集型別為何在實務中比聯集罕見得多,以及最常出現的實際場合。
TypeScript Fundamentals
#frontendMasters #typescriptFundamentals #TypeScript #IntersectionTypes #UnionTypes #ObjectAssign #SpreadOperator MIT Licensed | Copyright © 2025-present Wen-Hsiu's Blog
