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
optional chainingの話
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
yayoc
April 24, 2018
Programming
0
280
optional chainingの話
2018/04/24 Roppongi.js
yayoc
April 24, 2018
Tweet
Share
More Decks by yayoc
See All by yayoc
Proxy's Black Magic
yayoc
0
190
What I did to improve performance score on Lighthouse
yayoc
2
2.7k
Practical Flow Type
yayoc
1
780
Other Decks in Programming
See All in Programming
Pythonではじめるオープンデータ分析〜書籍の紹介と書籍で紹介しきれなかった事例の紹介〜
welliving
3
860
Patterns of Patterns
denyspoltorak
0
1.3k
MUSUBIXとは
nahisaho
0
110
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
280
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
CSC307 Lecture 05
javiergs
PRO
0
490
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
200
ゆくKotlin くるRust
exoego
1
220
AI 駆動開発ライフサイクル(AI-DLC):ソフトウェアエンジニアリングの再構築 / AI-DLC Introduction
kanamasa
11
6.1k
今から始めるClaude Code超入門
448jp
5
6.5k
ThorVG Viewer In VS Code
nors
0
750
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.2k
Featured
See All Featured
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
420
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
57
Site-Speed That Sticks
csswizardry
13
1k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
150
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.1k
Documentation Writing (for coders)
carmenintech
77
5.2k
From π to Pie charts
rasagy
0
120
Paper Plane
katiecoart
PRO
0
46k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
117
100k
Designing for Timeless Needs
cassininazir
0
120
Transcript
Optional chainingの話 Roppongi.js @yayoc
Hello! I am 弥吉修英 I am software engineer at Fast
Retailing. Twitter: @yayoc_ Github: @yayoc
なにをやっているか? ◦ SPAの実装 ◦ BFFの実装 ( 今日はここについての話など ) CDN router
SPA BFF Micro-service A Micro-service B Micro-service C Micro-service D
Micro serviceとの付き合い ◦ 10個以上のmicro serviceとREST APIでのやり取り ◦ APIがnullやundefinedを返すことはよくある □ データの不整合だったり・・
□ API仕様がPF間で若干違っていたり・・ □ バグだったり・・
結果、TypeError Cannot read propertyが頻出度の高いエラーであるという話 https://rollbar.com/blog/top-10-javascript-errors/ 肌感としてもよく分かる
解決策? 1. && operator 2. Ternary operator 3. Try catch
どれも冗長さが否めない・・
optional-chainingの proposal ◦ .? の左側を計算して、undefined もしくは nullの場合は、 undefinedを返す。そうでない場合は、素直にプロパティアク セスや関数実行を行う ◦
冗長な繰り返し記述やテンポラリな変数格納を避ける ◦ ステータスはStage1 ◦ Swift, C#などにはある ◦ https://tc39.github.io/proposal-optional-chaining/ ◦ TSにもまだない。( 議論は3年以上前からあるが・・ https://github.com/Microsoft/TypeScript/issues/16
optional-chain ◦ optional-chainというライブラリを作ってみた https://github.com/yayoc/optional-chain ◦ TSで書いたOption Typeを使った実装
optional-chain ◦ 間違ったプロパティアクセスに対しては、エラーを返す ◦ この辺の実装は@utatti氏のlens実装をかなり参考に
optional-chain ◦ パターンマッチ, getOrElseなどのAPIも一応ある
結論 ◦ JSにおける、プロパティアクセスは悩みのタネ ◦ optional chainingはスマートに解決してくれるので期待 ◦ optional-chainも解決してくれるかもしれない
THANKS! ありがとうございました。 Twitter: @yayoc_ Github: @yayoc
Appendix ◦ https://github.com/paypal/api-standards/blob/master /api-style-guide.md#null ◦ https://github.com/tc39/proposal-optional-chaining ◦ https://github.com/yayoc/optional-chain ◦ https://medium.com/@n_yayoshi/optional-chain-pro
xy-brings-optional-chaining-75fff102acbd ◦ https://developer.apple.com/library/content/docume ntation/Swift/Conceptual/Swift_Programming_Langu age/OptionalChaining.html
CREDITS Special thanks to all the people who made and
released these awesome resources for free: ◦ Presentation template by SlidesCarnival ◦ Photographs by Unsplash ◦ Backgrounds by SubtlePatterns