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
290
0
Share
optional chainingの話
2018/04/24 Roppongi.js
yayoc
April 24, 2018
More Decks by yayoc
See All by yayoc
Proxy's Black Magic
yayoc
0
210
What I did to improve performance score on Lighthouse
yayoc
2
2.8k
Practical Flow Type
yayoc
1
810
Other Decks in Programming
See All in Programming
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
140
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
1
550
Modding RubyKaigi for Myself
yui_knk
0
830
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
11
3.1k
inferと仲良くなる10分間
ryokatsuse
1
290
関係性から理解する"同一性"の型用語たち
pvcresin
2
620
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3k
AIチームを指揮するOSS「TAKT」活用術 / How to Use “TAKT,” an OSS Tool for Orchestrating AI Teams
nrslib
6
760
AIエージェントの隔離技術の徹底比較
kawayu
0
450
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
2
510
Zod v4 Codec でスキーマに型変換を埋め込む REST API 設計 #TSKaigi2026
ryutaro_yako
0
180
Inside Stream API
skrb
1
460
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
850
How to Think Like a Performance Engineer
csswizardry
28
2.6k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.6k
First, design no harm
axbom
PRO
2
1.2k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
RailsConf 2023
tenderlove
30
1.5k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
AI: The stuff that nobody shows you
jnunemaker
PRO
7
670
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
61
44k
Documentation Writing (for coders)
carmenintech
77
5.4k
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