I'm using TypeScript 1.4 in an ASP.NET MVC 5 project.
I have a field of type Date, and it works partially:
var dob: Date = result.dateOfBirth;
alert(dob);
var dobAsString = dob.toDateString();
In the code above, the first two lines work, showing the value as "1968-11-16T00:00:00", as expected. But the last line doesn't work, in fact the rest of the code below that line isn't even executed -- it just breaks, without error message.
This behavior persists no matter which Date function I apply in the last line; I could also use dob.getFullYear() etc. and it would fail every time. Yet the variable is of the right type and has the right value. The compiler also finds the Date functions, it compiles without a hitch but at runtime it fails. Any ideas?
result.dateOfBirthis really aDateobject and not a string representing a date? Is it possible there's atry/catcharound this code that is swallowing the error silently?try/catch, anddobis strongly-typed as aDate.resultthrough some fluke happens to have the number42or the string"carrot"as the value ofdateOfBirth, Typescript cannot detect this and work around it. Can youalert(typeof dob)oralert(Object.prototype.toString.call(dob))to verify that it is indeed what you think it should be?dateOfBirthproperty is aDate", the compiler will believe you, and there won't be any runtime code to verify this.