1

I have a type delared like this:

export type monetaryValue = {
  currency?: string;
  value?: string;
};

How can I iterate over the declared properties? The actual goal I'm trying to achieve is to check if an object deserialized from JSON contains all properties of given type (all are not undefined).

adam.k
  • 324
  • 3
  • 14
  • If you cast the deseralized object to the type moentaryValue you can then use Object.Values to ensure that nothing is undefined; – Alex Apr 27 '22 at 12:25
  • @Alex I'm new to typescript but if I cast it like this: `const myCastObj = myObj as monetaryValue ;` it's not adding the 2 props if it didn't have them before. So I can't use Objec.values to check if they are undefined. – adam.k Apr 27 '22 at 12:46
  • Typescript is not runtime, meaning, it will not know how to 'instantiate' a new item for you. The typing is exclusively for developers. I think you are looking for how to deseralize json into a JS Class. You can then type this class with your custom type. – Alex Apr 28 '22 at 10:56

0 Answers0