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
GraphQLの魅力を引き出すAndroidクライアント実装
morux2
3
420
Why Prism?
kddnewton
4
1.7k
ブラウザ互換の重要性 - あらゆるユーザーに価値を届けるために必要なこと
yamanoku
0
110
Android開発以外のAndroid開発経験の活かしどころ
konifar
2
840
How to Break into Reading Open Source
kaspth
1
210
A New Era of Testing
mannodermaus
2
320
The Shape of a Service Object
inem
0
510
What you can do with Ruby on WebAssembly
kateinoigakukun
0
160
Some more adventure of Happy Eyeballs
coe401_
2
180
ドメイン駆動設計を実践するために必要なもの
bikisuke
4
330
connect-go で面倒くささと戦う / 2024-08-27 #newmo_layerx_go
izumin5210
2
630
Our Websites Need a Lifestyle Change, Not a Diet
ryantownsend
0
140
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
25
3.9k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
24
600
Designing with Data
zakiwarfel
98
5k
The Power of CSS Pseudo Elements
geoffreycrofte
71
5.2k
Fontdeck: Realign not Redesign
paulrobertlloyd
80
5.1k
No one is an island. Learnings from fostering a developers community.
thoeni
18
2.9k
Clear Off the Table
cherdarchuk
91
320k
Speed Design
sergeychernyshev
22
430
Building an army of robots
kneath
302
42k
Navigating Team Friction
lara
183
13k
Typedesign – Prime Four
hannesfritz
39
2.3k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
248
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