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
600
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.3k
WebHID API でリングコン のセンサー値を取得してみた
mascii
1
790
Pros and Cons で考える Vue 2 Composition API
mascii
4
890
Joy-ConをJavaScriptでプレゼンリモコンにした話
mascii
0
410
Vue.jsでCSS Modulesを使ってみた
mascii
0
120
不変量
mascii
1
100
Nuxt.js+Firebaseで個人サービスを作るまで
mascii
1
2.1k
JavaScriptのバージョンの話
mascii
1
1.9k
あなたのお家に眠るラズパイを救出したい
mascii
4
2.8k
Other Decks in Programming
See All in Programming
Git Rebase
bkuhlmann
11
1.6k
GitHub Copilotのススメ
marcy731
1
200
Let's learn code review
riofujimon
2
410
Micro Frontends for Java Microservices - Devnexus 2024
mraible
PRO
0
490
Ruby Function Composition
bkuhlmann
1
330
サイコロで理解する統計的仮説検定の考え方
tatamiya
4
950
Apache Hive 4 on Treasure Data
ryukobayashi
0
330
見た目から始める生産性向上
ikumatadokoro
7
850
はてなにおける CSS Modules、及び CSS Modules に足りないもの / CSS Modules in Hatena, and CSS Modules missing parts
mizdra
7
930
エンターテイメント業界で利用されるAWS
demuyan
0
210
educure_カリキュラム生操作マニュアル.pdf
linew_official
0
810
冗長なエラーログを削減し、スタックトレースを手に入れる / Reducing Verbose Error Logs and Obtaining Stack Traces
upamune
0
770
Featured
See All Featured
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
2
1.3k
The Brand Is Dead. Long Live the Brand.
mthomps
49
29k
The World Runs on Bad Software
bkeepers
PRO
61
6.7k
What the flash - Photography Introduction
edds
64
11k
Optimising Largest Contentful Paint
csswizardry
8
2.4k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
221
21k
Music & Morning Musume
bryan
41
5.6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
125
32k
A better future with KSS
kneath
231
16k
Building Applications with DynamoDB
mza
88
5.6k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
20
1.9k
The Illustrated Children's Guide to Kubernetes
chrisshort
31
46k
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