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
TypeScript で Optional Chaining を使ってみた
Search
Masaki Koyanagi
October 25, 2019
Programming
1
730
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
Vitestを使った型テストの始め方
mascii
6
2.8k
WebHID API でリングコン のセンサー値を取得してみた
mascii
1
1k
Pros and Cons で考える Vue 2 Composition API
mascii
4
1.1k
Joy-ConをJavaScriptでプレゼンリモコンにした話
mascii
0
550
Vue.jsでCSS Modulesを使ってみた
mascii
0
140
不変量
mascii
1
170
Nuxt.js+Firebaseで個人サービスを作るまで
mascii
1
2.4k
JavaScriptのバージョンの話
mascii
1
2.2k
あなたのお家に眠るラズパイを救出したい
mascii
4
3k
Other Decks in Programming
See All in Programming
プロダクト開発でも使おう 関数のオーバーロード
yoiwamoto
0
120
Perplexity Slack Botを作ってAI活用を進めた話 / AI Engineering Summit プレイベント
n3xem
0
350
セキュリティマネジャー廃止とクラウドネイティブ型サンドボックス活用
kazumura
1
150
❄️ tmux-nixの実装を通して学ぶNixOSモジュール
momeemt
1
150
List Unfolding - 'unfold' as the Computational Dual of 'fold', and how 'unfold' relates to 'iterate'"
philipschwarz
PRO
0
170
#QiitaBash TDDでAIに設計イメージを伝える
ryosukedtomita
2
1.6k
PT AI без купюр
v0lka
0
210
JSAI2025 RecSysChallenge2024 優勝報告
unonao
1
420
型付け力を強化するための Hoogle のすゝめ / Boosting Your Type Mastery with Hoogle
guvalif
1
250
ktr0731/go-mcpでMCPサーバー作ってみた
takak2166
0
110
Babylon.js 8.0のアプデ情報を 軽率にキャッチアップ / catch-up-babylonjs-8
drumath2237
0
120
Feature Flag 自動お掃除のための TypeScript プログラム変換
azrsh
PRO
4
660
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.3k
For a Future-Friendly Web
brad_frost
178
9.8k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
60k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
770
Rebuilding a faster, lazier Slack
samanthasiow
81
9k
Designing for Performance
lara
608
69k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
106
19k
Done Done
chrislema
184
16k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.5k
RailsConf 2023
tenderlove
30
1.1k
Stop Working from a Prison Cell
hatefulcrawdad
269
20k
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