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
Typescript5.4の新機能
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
rakus frontend
April 21, 2024
350
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
56
ErrorBoundaryとSuspenseの導入検討
rakus_fe
1
820
日付をもう少し真面目に勉強中
rakus_fe
0
56
React19 β をざっと見る
rakus_fe
0
360
Reactのパフォーマンス改善例
rakus_fe
0
590
非破壊的な配列メソッド
rakus_fe
0
420
ココがすごいぜ!Playwright Component Test
rakus_fe
0
630
スプレッドシートのセル結合がつらいので足掻いてみた話
rakus_fe
0
290
Featured
See All Featured
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.8k
Mobile First: as difficult as doing things right
swwweet
225
10k
Evolving SEO for Evolving Search Engines
ryanjones
0
220
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
250
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
170
Color Theory Basics | Prateek | Gurzu
gurzu
0
370
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
580
Chasing Engaging Ingredients in Design
codingconduct
0
230
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
330
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
190
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→いまいち使い所が思いつかなかった… ・型の絞り込み→役立つが場面ができてきそうだと思った