//I am working on this assignment objToSendServer.input1 = obj.input1 //type definitions are: class obj { input1: number; } class objToSendServer{ input1: number } // if I do this assignment that value of obj.input1 is "1" // which cause of problem on server side // which is web api odata, patch method that expects type of int objToSendServer.input1 = obj.input1; // if I try cast as below, error message is: //Argument of type 'number' is not assingable of parameter of type 'string' objToSendServer.input1 = parseFloat(obj.input1); //My work around is: objToSendServer.input1 = parseFloat(obj.input1.toString()); I suppose that type cast would be done automatically which is not case here.
So my question is there better approach to this type of assignment
Also if obj.input1 is null this workaround fails.
TypeError: Cannot read property 'toString' of null Then I should check if obj.input1 is null or not
Note: I edited the title which was Is there "automatic" type cast in typescript to express issue more clear