Breeze类型的getProperty方法不适用于Typescript

Breeze type getProperty method does not work with Typescript

本文关键字:不适用 适用于 Typescript 方法 getProperty 类型 Breeze      更新时间:2023-09-26

微风文档显示了这一点,以获取实体上属性的属性类型:

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

但如果您使用的是Typescript,这是不起作用的。

MetadataStore.getEntityType的类型定义返回一个IStructuralType。但getPropertyEntityType上而不在IStructuralType上。

EntityType确实实现了IStructuralType,但不能保证IStructuralTypeEntityType

这是Breeze的打字错误吗?或者有其他方法可以调用这个方法吗

您有两个选项:

  1. 铸造:em.metadataStore.getEntityType("Person") as EntityType;
  2. 更改getEntityType的定义以在.d.ts文件中返回EntityType

请记住,更改类型信息总是安全的——最糟糕的情况是导致TypeScript编译错误。这是因为所有类型信息都被擦除了。(异常是更改类的名称或扩展,因为它被编译为js。)