When using typescript, the declared interface might look like this:
interface MyInterface { test: string; }
And an implementation with an additional property might be something like this:
class MyTest implements MyInterface { test: string; newTest: string; }
Example (here the "reduced" variable still contains the "newTest" property):
var test: MyTest = {test: "hello", newTest: "world"} var reduced: MyInterface = test; // something clever is needed
Question
In general, how can you make the "reduced" variable contain only properties declared in the "MyInterface" interface.
Why
The problem arises when trying to use a "reduced" variable with angular.toJson before sending it to the recreation service - the toJson method converts the new variable newTest, even if it is not available in the instance at compile time, and this forces the service to not accept json because he possesses properties that should not be.
javascript angularjs typescript
Tomas f
source share