LearningTypeScript / site

Companion website for the Learning TypeScript book.
https://learningtypescript.com
MIT License
48 stars 12 forks source link

📝 Article: the difference between optional chaining and non-null assertions #69

Open JoshuaKGoldberg opened 2 years ago

JoshuaKGoldberg commented 2 years ago

Overview

?. and !. aren't the same. I should write an article explaining the difference.

One common slipup I've seen is people doing this:

const myValue = document.getElementById(someId)?.textContent;

...and wondering why myValue is string | undefined, not string.