I'm using Breeze + Typescript + Knockout for a Spa, and I'm facing the following problem: when I create a new entity with EntityManager.createEntity, typescript doesn't let me use the observables that Breeze generates from metadata. Typescript "sees" only the "entityAspect" and the "entityType" properties. I'm using the type definitions of DefinitelyTyped. Any help is greatly appreciated!
You can create an interface for your type which extends breeze.Entity
:
/// <reference path="breeze.d.ts" />
module model {
export interface ResponsesItem extends breeze.Entity {
ContentTypeID: string;
Title: string;
Description: string;
EventDate: any;
/* etc. */
}
}
You can then cast your objects to this interface whenever you need to work with them in a typed way, such as the result of a query when loading from the server :
private loadResponses(): void {
this.dataservice.ListResponses()
.then((data: { results: breeze.Entity[]; query: breeze.EntityQuery; XHR: XMLHttpRequest; }) => {
var results: model.ResponsesItem[] = <model.ResponsesItem[]>data.results;
// Do something with typed results array here.
}).fail((error) => {
this.handleDataError(error);
});
}
Check out my answer at Breeze.js typed entities wherein I hacked T4TS to spit out TS definitions that support Breeze.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With