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
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
770
Other Decks in Programming
See All in Programming
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
550
Combinatorial Interview Problems with Backtracking Solutions - From Imperative Procedural Programming to Declarative Functional Programming - Part 2
philipschwarz
PRO
0
130
TestingOsaka6_Ozono
o3
0
240
脳の「省エネモード」をデバッグする ~System 1(直感)と System 2(論理)の切り替え~
panda728
PRO
0
130
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
230
ゆくKotlin くるRust
exoego
1
180
クラウドに依存しないS3を使った開発術
simesaba80
0
200
まだ間に合う!Claude Code元年をふりかえる
nogu66
5
920
Navigation 3: 적응형 UI를 위한 앱 탐색
fornewid
1
510
AIの誤りが許されない業務システムにおいて“信頼されるAI” を目指す / building-trusted-ai-systems
yuya4
6
4.1k
愛される翻訳の秘訣
kishikawakatsumi
3
360
CSC307 Lecture 02
javiergs
PRO
1
710
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
Rails Girls Zürich Keynote
gr2m
95
14k
So, you think you're a good person
axbom
PRO
0
1.9k
Balancing Empowerment & Direction
lara
5
830
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.1k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
37
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
96
Darren the Foodie - Storyboard
khoart
PRO
0
2k
30 Presentation Tips
portentint
PRO
1
180
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
180
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