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
680
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
940
Pros and Cons で考える Vue 2 Composition API
mascii
4
1k
Joy-ConをJavaScriptでプレゼンリモコンにした話
mascii
0
510
Vue.jsでCSS Modulesを使ってみた
mascii
0
130
不変量
mascii
1
140
Nuxt.js+Firebaseで個人サービスを作るまで
mascii
1
2.3k
JavaScriptのバージョンの話
mascii
1
2.1k
あなたのお家に眠るラズパイを救出したい
mascii
4
3k
Other Decks in Programming
See All in Programming
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
280
Beyond ORM
77web
7
920
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.7k
Haze - Real time background blurring
chrisbanes
1
510
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
140
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1k
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
190
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
160
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
500
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
390
良いユニットテストを書こう
mototakatsu
8
2.7k
Featured
See All Featured
Making Projects Easy
brettharned
116
5.9k
A better future with KSS
kneath
238
17k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Speed Design
sergeychernyshev
25
670
Typedesign – Prime Four
hannesfritz
40
2.4k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Docker and Python
trallard
42
3.1k
Rails Girls Zürich Keynote
gr2m
94
13k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
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