Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Typescript5.4の新機能
Search
rakus frontend
April 21, 2024
370
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Typescript5.4の新機能
rakus frontend
April 21, 2024
More Decks by rakus frontend
See All by rakus frontend
新卒FEが1年目に取り組んだこと・学んだこと
rakus_fe
0
60
ErrorBoundaryとSuspenseの導入検討
rakus_fe
1
860
日付をもう少し真面目に勉強中
rakus_fe
0
58
React19 β をざっと見る
rakus_fe
0
380
Reactのパフォーマンス改善例
rakus_fe
0
620
非破壊的な配列メソッド
rakus_fe
0
440
ココがすごいぜ!Playwright Component Test
rakus_fe
0
670
スプレッドシートのセル結合がつらいので足掻いてみた話
rakus_fe
0
310
Featured
See All Featured
Visualization
eitanlees
153
17k
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Writing Fast Ruby
sferik
630
63k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
310
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
Balancing Empowerment & Direction
lara
6
1.3k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
460
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
440
Accessibility Awareness
sabderemane
1
260
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
How STYLIGHT went responsive
nonsquared
100
6.3k
Transcript
TypeScript5.4の新機能 村山陽亮
型の絞り込み 5.4以前 function getUrls(url: string | URL, names: string[]) {
if (typeof url === "string") { url = new URL(url); } return names.map(name => { // if (typeof url === "string") return; url.searchParams.set("name", name); return url.toString(); }); } 関数クロージャ内で型情報が 保持されなかった 関数内でもう一度型情報 を絞り込む必要がなくなっ た
型の絞り込み 注意点 function printValueLater(value: string | undefined) { // ここで呼び出すことが可能
// toUpperCaseFn(); if (value === undefined) { value = "missing!"; } function toUpperCaseFn() { // エラーが発生する console.log(value.toUpperCase()); } // エラーは発生しない const toUpperCaseFn2 = () => console.log(value.toUpperCase()); } functionで関数宣言をした場 合、ホイスティングができるた め、型情報は保持されない
NoInfer ・5.4から新しく追加されたユーティリティ型 ・不要な型推論をブロックすることができる function createStreetLight<C extends string>(colors: C[], defaultColor?: C)
{ // ... } // blueはcolorsの配列に含まれていないのにエラーにならない createStreetLight(["red", "yellow", "green"], "blue"); // defaultColorからCが推論されるのを防ぐ function createStreetLight<C extends string>(colors: C[], defaultColor?: NoInfer<C>) { // ... }
まとめ ・NoInfer→いまいち使い所が思いつかなかった… ・型の絞り込み→役立つが場面ができてきそうだと思った