Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
TypeScriptのextends
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
MisakiSoeda
April 23, 2025
Programming
48
0
Share
TypeScriptのextends
MisakiSoeda
April 23, 2025
Other Decks in Programming
See All in Programming
AIエージェントで業務改善してみた
taku271
0
470
VueエンジニアがReactを触って感じた_設計の違い
koukimiura
0
160
ネイティブアプリとWebフロントエンドのAPI通信ラッパーにおける共通化の勘所
suguruooki
0
250
車輪の再発明をしよう!PHP で実装して学ぶ、Web サーバーの仕組みと HTTP の正体
h1r0
3
500
PHPで TLSのプロトコルを実装してみる
higaki_program
0
740
20260313 - Grafana & Friends Taipei #1 - Kubernetes v1.36 的開發雜記:那些困在 Alpha 加護病房太久的 Metrics
tico88612
0
250
Strategy for Finding a Problem for OSS: With Real Examples
kibitan
0
140
The Monolith Strikes Back: Why AI Agents ❤️ Rails Monoliths
serradura
0
190
Kubernetesでセルフホストが簡単なNewSQLを求めて / Seeking a NewSQL Database That's Simple to Self-Host on Kubernetes
nnaka2992
0
200
Vibe하게 만드는 Flutter GenUI App With ADK , 박제창, BWAI Incheon 2026
itsmedreamwalker
0
540
Radical Imagining - LIFT 2025-2027 Policy Agenda
lift1998
0
240
ポーリング処理廃止によるイベント駆動アーキテクチャへの移行
seitarof
3
1.3k
Featured
See All Featured
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
710
[SF Ruby Conf 2025] Rails X
palkan
2
920
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
Navigating Team Friction
lara
192
16k
The Curse of the Amulet
leimatthew05
1
11k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
160
Into the Great Unknown - MozCon
thekraken
40
2.3k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
199
73k
How to build a perfect <img>
jonoalderson
1
5.3k
Test your architecture with Archunit
thirion
1
2.2k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
160
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Transcript
!.JTBLJ4PFEB 5ZQF4DSJQUͷFYUFOET .JUBUT
.JTBLJ4PFEB ൃදऀ גࣜձࣾ#PPL-JWF ٕज़։ൃຊ෦γεςϜ։ൃ෦ετΞ։ൃνʔϜ ϑϩϯτΤϯυΤϯδχΞ 5ZQF4DSJQUͰझຯͰόοΫΤϯυॻ͍ͨΓ͍ͯ͠Δ 5ZQF4DSJQU͕͖ʂ ͷ54,BJHJ͔ΒελοϑΛ͍ͯ͠Δ
ͳͥ͜ͷςʔϚʹͨ͠ͷ͔
ʮܕ҆શͬͯɺͲ͏ਂ۷Γ͢ΔΜͩΖ͏ʁʯ w UZQFDIBMMFOHFTʹઓΛ࢝ΊΔʂ w UZQFDIBMMFOHFTΛ௨ͯ͠ؾ͍ͮͨͷ͕ɺܕϨϕϧͰͷߜΓࠐΈૢ࡞͕ܕ҆ શੑΛܶతʹߴΊͯ͘ΕΔͱ͍͏͜ͱɻ w ಛʹFYUFOETΛͬͨܕૢ࡞͕ҹతͰͨ͠ɻ
FYUFOETͷجຊ
FYUFOETͷجຊ w ܕҾ w Ϋϥεͷܧঝ
FYUFOETͷجຊ w ܕҾɹˡͪ͜Βͷ͓ w Ϋϥεͷܧঝ
FYUFOETͷجຊ T extends U ? X : Y w FYUFOETʮܕ͕݅Λຬ͍ͨͯ͠Δ͔ʁʯΛஅ͢Δ݅ܕͷΩʔߏจɻ
w ଞͷUZQFPGJO͕࣮ߦ࣌ͷʹج͍ͮͯܕΛߜΓࠐΉͷʹର͠ɺ FYUFOETΛͬͨ݅ܕ ʮܕͦͷͷ͚ͩΛݟͯॲཧΛ͚Δʯ७ਮͳܕϨϕϧͷذͰ͢ɻ
ྫ6OJPOܕͷϑΟϧλϦϯά త6OJPO͔Βಛఆͷܕ͚ͩநग़ type OnlyStrings<T> = T extends string ? T
: never; type Mixed = "hello" | 42 | "world"; type JustStrings = OnlyStrings<Mixed>; // "hello" | "world" 6OJPOܕʹରͯ͠5FYUFOETʜͱॻ͘ͱɺ֤ߏཁૉʹରͯ͠ݸผʹධՁ͞ ΕΔlzͱ͍͏༷͕͋Γ·͢ɻ
ྫΦϒδΣΫτͷܕΛಛఆ͢Δ తಛఆͷϓϩύςΟΛ࣋ͭܕ͚ͩΛநग़ type Event = | { type: "click"; x:
number } | { type: "scroll"; y: number }; type ExtractByType<T, K extends string> = T extends { type: K } ? T : never; type ClickEvent = ExtractByType<Event, "click">; // => { type: "click"; x: number }
ྫFYUFOETͷ͍ํʢ੍ˍ݅ܕʣ // ੍ͱͯ͠ͷextends function logLength<T extends { length: number }>(value:
T) { console.log(value.length); } // ݅ܕͱͯ͠ͷextends type OnlyStrings<T> = T extends string ? T : never;
݅ܕͰͷFYUFOETͷϝϦοτ w ܕͷ҆શੑ্͕ʢ༧ظ͠ͳ͍ܕΛ͚Δʣ w ॊೈͳܕૢ࡞͕Ͱ͖ΔʢܕϨϕϧͰ fi MUFSNBQ͕Մೳʣ w ܕਪ͕ਖ਼֬ʹͳΔʢิ͕ޮ͖͘͢ͳΔʣ
·ͱΊ
·ͱΊ w ܕϨϕϧͷૢ࡞ܕ҆શੑͷ伴ʂ w ݅ܕʹΑΔFYUFOETɺܕͷذɾબʹڧྗɻ w UZQFDIBMMFOHFTͰɺܕͷײ֮Λ͑Δͷ͓͢͢Ίʂ