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
640
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
5
2.5k
WebHID API でリングコン のセンサー値を取得してみた
mascii
1
910
Pros and Cons で考える Vue 2 Composition API
mascii
4
970
Joy-ConをJavaScriptでプレゼンリモコンにした話
mascii
0
470
Vue.jsでCSS Modulesを使ってみた
mascii
0
130
不変量
mascii
1
130
Nuxt.js+Firebaseで個人サービスを作るまで
mascii
1
2.2k
JavaScriptのバージョンの話
mascii
1
2.1k
あなたのお家に眠るラズパイを救出したい
mascii
4
2.9k
Other Decks in Programming
See All in Programming
Ebitengineの1vs1ゲーム WebRTCの活用
ponyo877
0
380
メモリ最適化を究める!iOSアプリ開発における5つの重要なポイント
yhirakawa333
0
420
LangChainでWebサイトの内容取得やGitHubソースコード取得
shukob
0
160
React + TextAliveでカッコいいLyric Applicatioinを作ろう!!
tosuri13
0
400
How to Break into Reading Open Source
kaspth
2
210
watsonx.ai Dojo #2 生成AIを使ったアプリ開発入門編
oniak3ibm
PRO
0
180
Ruby Parser progress report 2024
yui_knk
2
230
Modular Monolith Go Server with GraphQL Federation + gRPC
110y
1
580
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
0
120
From Idea to IDE: Developing Plugins for Android Studio
thisaay
1
220
Rubyとクリエイティブコーディングの輪の広がり / The Growing Circle of Ruby and Creative Coding
chobishiba
1
270
大公開!iOS開発の悩みトップ5 〜iOSDC Japan 2024〜
ryunakayama
0
190
Featured
See All Featured
Code Review Best Practice
trishagee
62
16k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
25
3.9k
Statistics for Hackers
jakevdp
794
220k
Robots, Beer and Maslow
schacon
PRO
157
8.2k
Practical Orchestrator
shlominoach
185
10k
The Power of CSS Pseudo Elements
geoffreycrofte
71
5.3k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.4k
A Philosophy of Restraint
colly
202
16k
How To Stay Up To Date on Web Technology
chriscoyier
786
250k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
43
2k
Web development in the modern age
philhawksworth
205
10k
Writing Fast Ruby
sferik
623
60k
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