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
700
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.7k
WebHID API でリングコン のセンサー値を取得してみた
mascii
1
960
Pros and Cons で考える Vue 2 Composition API
mascii
4
1.1k
Joy-ConをJavaScriptでプレゼンリモコンにした話
mascii
0
530
Vue.jsでCSS Modulesを使ってみた
mascii
0
140
不変量
mascii
1
150
Nuxt.js+Firebaseで個人サービスを作るまで
mascii
1
2.3k
JavaScriptのバージョンの話
mascii
1
2.2k
あなたのお家に眠るラズパイを救出したい
mascii
4
3k
Other Decks in Programming
See All in Programming
React 19アップデートのために必要なこと
uhyo
8
1.6k
未経験でSRE、はじめました! 組織を支える役割と軌跡
curekoshimizu
1
200
sappoRo.R #12 初心者セッション
kosugitti
0
280
クリーンアーキテクチャから見る依存の向きの大切さ
shimabox
5
1.1k
DRFを少しずつ オニオンアーキテクチャに寄せていく DjangoCongress JP 2025
nealle
2
290
読まないコードリーディング術
hisaju
0
120
CDKを使ったPagerDuty連携インフラのテンプレート化
shibuya_shogo
0
120
iOSでQRコード生成奮闘記
ktcryomm
2
130
楽しく向き合う例外対応
okutsu
0
730
.NET Frameworkでも汎用ホストが使いたい!
tomokusaba
0
210
Go 1.24でジェネリックになった型エイリアスの紹介
syumai
2
300
Webフレームワークとともに利用するWeb components / JSConf.jp おかわり
spring_raining
1
130
Featured
See All Featured
Gamification - CAS2011
davidbonilla
80
5.2k
How to train your dragon (web standard)
notwaldorf
91
5.9k
GraphQLの誤解/rethinking-graphql
sonatard
69
10k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
4
440
RailsConf 2023
tenderlove
29
1k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
A Tale of Four Properties
chriscoyier
158
23k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Building Adaptive Systems
keathley
40
2.4k
How GitHub (no longer) Works
holman
314
140k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.2k
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