typescript - Date variable works, but functions on it do not -


i'm using typescript 1.4 in asp.net mvc 5 project.

i have field of type date, , works partially:

var dob: date = result.dateofbirth; alert(dob); var dobasstring = dob.todatestring(); 

in code above, first 2 lines work, showing value "1968-11-16t00:00:00", expected. last line doesn't work, in fact rest of code below line isn't executed -- breaks, without error message.

this behavior persists no matter date function apply in last line; use dob.getfullyear() etc. , fail every time. yet variable of right type , has right value. compiler finds date functions, compiles without hitch @ runtime fails. ideas?

there 2 aspects one. first need parse date, have string representation currently. second result variable doesn't have type information.

var result = {     dateofbirth: '1968-11-16t00:00:00' };  // error, cannot convert string date var a: date = result.dateofbirth;  // okay var b: date = new date(result.dateofbirth);  var result2: = result;  // okay (not type information result2) var c: date = result2.dateofbirth; 

when json message, can apply interface describes server has send, in order catch problems in typescript code - such 1 found. stop problem occurring again in future (although doesn't check supplied json matches interface)... example below assumes result has any type.

interface nameyourresult {     dateofbirth: string; }  var r: nameyourresult = result; 

Comments