0
votes

The breeze docs show this to get the property type for a property on an entity:

//get the Person type
var personType = em.metadataStore.getEntityType("Person"); 
//get the property definition to validate
var websiteProperty = personType.getProperty("website"); 

But if you are using Typescript this does not work.

The type definitions for MetadataStore.getEntityType returns an IStructuralType. But getProperty is on EntityType and not on IStructuralType.

EntityType does implement IStructuralType, but there is no guarantee that the IStructuralType is an EntityType.

Is this an error in the typing for Breeze? Or is there another way to get this method call?

1

1 Answers

1
votes

You have two options:

  1. Cast it: em.metadataStore.getEntityType("Person") as EntityType;
  2. Change the definition of getEntityType to return an EntityType in your .d.ts file

Keep in mind that changing type information is always safe - the worst you can ever do is cause a TypeScript compile error. This is because all type information is erased. (The exception is changing the name or extends of a class, since that is compiled to js.)