I'm trying to understand TypeScript better. I've found that if I write a bug like so:
function doStuff() {
if (physician.email == "[email protected]")
{
var physician = {email: "[email protected]", name: "Dr. Bob"};
/* .... */
} }
TypeScript will NOT catch the problem that the physician object is defined AFTER we attempted to use one of its properties. This results in a run-time error of:
Type error: Cannot read property 'email' of undefined.
Why doesn't the TypeScript transpiler catch stuff like this? Using TypeScript 2.0 I believe.
var. It's a lot harder to accidentally cause bugs like this if you can't use the variable before declaring it.