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
360
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
59
ErrorBoundaryとSuspenseの導入検討
rakus_fe
1
850
日付をもう少し真面目に勉強中
rakus_fe
0
58
React19 β をざっと見る
rakus_fe
0
370
Reactのパフォーマンス改善例
rakus_fe
0
610
非破壊的な配列メソッド
rakus_fe
0
430
ココがすごいぜ!Playwright Component Test
rakus_fe
0
650
スプレッドシートのセル結合がつらいので足掻いてみた話
rakus_fe
0
300
Featured
See All Featured
Amusing Abliteration
ianozsvald
1
310
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
We Are The Robots
honzajavorek
0
380
The SEO identity crisis: Don't let AI make you average
varn
0
560
Faster Mobile Websites
deanohume
310
32k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
700
Navigating Team Friction
lara
192
16k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
530
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
エンジニアに許された特別な時間の終わり
watany
109
250k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
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→いまいち使い所が思いつかなかった… ・型の絞り込み→役立つが場面ができてきそうだと思った