Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
TypeScript で Optional Chaining を使ってみた
Masaki Koyanagi
October 25, 2019
Programming
1
460
TypeScript で Optional Chaining を使ってみた
WeJS @ 37th
https://wajs.connpass.com/event/150356/
Masaki Koyanagi
October 25, 2019
Tweet
Share
More Decks by Masaki Koyanagi
See All by Masaki Koyanagi
WebHID API でリングコン のセンサー値を取得してみた
mascii
1
470
Pros and Cons で考える Vue 2 Composition API
mascii
4
560
Joy-ConをJavaScriptでプレゼンリモコンにした話
mascii
0
260
Vue.jsでCSS Modulesを使ってみた
mascii
0
77
不変量
mascii
1
60
Nuxt.js+Firebaseで個人サービスを作るまで
mascii
1
1.5k
JavaScriptのバージョンの話
mascii
1
1.4k
あなたのお家に眠るラズパイを救出したい
mascii
4
2.6k
Node.js + Raspberry Piで お手軽IoT
mascii
2
1.3k
Other Decks in Programming
See All in Programming
よりUXに近いSLI・SLOの運用による可用性の再設計
kazumanagano
3
890
Quartoを使ってみませんか / quarto_get_started
s_uryu
2
380
Android入門
hn410
0
310
Learning DDD輪読会#4 / Learning DDD Book Club #4
suzushin54
1
160
マイクロサービスプラットフォーム向け負荷試験基盤の初期リリースを終えた話
yuyu_hf
PRO
0
140
Architectural practices for greater scalability and innovation
otaviojava
0
100
Microsoft Teams の 会議アプリ開発のはじめかた / How to start Microsoft Teams app development
karamem0
0
1.7k
[RailsConf 2022] The pitfalls of realtime-ification
palkan
0
290
「新卒だけ」じゃない!学び直しを支えるミクシィの技術研修を紹介
mixi_engineers
PRO
0
180
Oculus Interaction SDK 概説 / xrdnk-caunity-LT4
xrdnk
0
270
Jakarta EE 10 is Coming Your Way
ivargrimstad
0
3.1k
WindowsコンテナDojo:第2回 Windowsコンテナアプリのビルド、公開、デプロイ
oniak3ibm
PRO
0
150
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
9
1.1k
Fashionably flexible responsive web design (full day workshop)
malarkey
396
62k
Visualization
eitanlees
124
11k
Six Lessons from altMBA
skipperchong
14
1.3k
Building Your Own Lightsaber
phodgson
94
4.6k
YesSQL, Process and Tooling at Scale
rocio
157
12k
The Web Native Designer (August 2011)
paulrobertlloyd
74
1.9k
How New CSS Is Changing Everything About Graphic Design on the Web
jensimmons
212
11k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
100
5.9k
Writing Fast Ruby
sferik
612
57k
Design by the Numbers
sachag
271
17k
Optimizing for Happiness
mojombo
365
63k
Transcript
None
• • •
• •
None
const user1 = { age: 26, driverLicense: { expirationDate: '2023/01/22'
}, } const user2 = { age: 12, driverLicense: null, } user1.driverLicense.expirationDate // '2023/01/22' user2.driverLicense.expirationDate // TypeError: Cannot read property 'expirationDate' of null
•
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Optional_chaining
const user1 = { age: 26, driverLicense: { expirationDate: '2023/01/22'
}, } const user2 = { age: 12, driverLicense: null, } user1.driverLicense?.expirationDate // '2023/01/22' user2.driverLicense?.expirationDate // undefined
• let expirationDate if (user.driverLicense) { expirationDate = user.driverLicense.expirationDate }
None
None
• ◦ https://devblogs.microsoft.com/typescript/announcing-typescript-3-7-rc/
https://devblogs.microsoft.com/typescript/ announcing-typescript-3-7-rc/ http://www.typescriptlang.org/play/
• "use strict"; var _a, _b; const foo = {
bar: null }; // foo?.bar?.baz (_b = (_a = foo) === null || _a === void 0 ? void 0 : _a.bar) === null || _b === void 0 ? void 0 : _b.baz;
• • const foo = { items: ['Pen', 'Pineapple', 'Apple'],
get bar() { console.count('bar!'); return { baz: this.items.join() }; } } foo?.bar?.baz // bar!: 1 // 'Pen,Pineapple,Apple' foo && foo.bar && foo.bar.baz // bar!: 2 // bar!: 3 // 'Pen,Pineapple,Apple'
• • $ npm i typescript@rc ts-node $ npx ts-node
None