angularjs - How to reduce javascript object to only contain properties from interface -


when using typescript declared interface this:

interface myinterface {   test: string; } 

and implementation property this:

class mytest implements myinterface {   test: string;   newtest: string; } 

example (here variable 'reduced' still contain property 'newtest'):

var test: mytest = {test: "hello", newtest: "world"}  var reduced: myinterface = test; // clever needed 

question

in general way, how can make 'reduced' variable contain properties declared in 'myinterface' interface.

why

the problem occur when trying use 'reduced' variable angular.tojson before sending rest service - tojson method transforms newtest variable, if it's not accessible on instance during compile, , makes rest service not accept json since has properties shouldn't there.

in example newtest property won't accessible thru reduced variable, that's goal of using types. typescript brings type checking, doesn't manipulates object properties.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -