4 ms·
2.0 added an exclamation mark (!) postfix operator that asserts a type as being non-null/non-undefined. So these checks are easy to explicitly ignore.
by Ycros 9y ago
2.0 added an exclamation mark (!) postfix operator that asserts a type as being non-null/non-undefined. So these checks are easy to explicitly ignore.
- technion 9y agoThanks! I wasn't aware of that. That said, I don't actually want to ignore it - I think it's good that Typescript is showing people some potentially errors they never thought to look for. This pattern really isn't hard and if it saves you from one "undefined is undefined" then it was worth it. const item = document.getElementById("content"); if (item == null) { console.log("Render container missing");