diegomvh / angular-odata

Client side OData typescript library for Angular
https://www.npmjs.com/package/angular-odata
MIT License
50 stars 14 forks source link

This package has errors during build. #17

Closed icapri closed 3 years ago

icapri commented 3 years ago

I run ng build to my project and I am receiving the following error message:

ERROR in node_modules/angular-odata/lib/resources/requests/action.d.ts:32:5 - error TS2416: Property 'post' in type 'ODataActionResource<P, R>' is not assignable to the same property in base type 'ODataResource<R>'. 
  Type '{ (body: P | null, options: HttpEntityOptions): Observable<ODataEntity<R>>; (body: P | null, options: HttpEntitiesOptions): Observable<...>; (body: P | null, options: HttpPropertyOptions): Observable<...>; }' is not assignable to type '(attrs: Partial<R>, options: HttpOptions & { responseType?: "arraybuffer" | "blob" | "value" | "property" | "entity" | "entities" | undefined; withCount?: boolean | undefined; }) => Observable<...>'.
    Types of parameters 'body' and 'attrs' are incompatible.
      Type 'Partial<R>' is not assignable to type 'P'.
        'P' could be instantiated with an arbitrary type which could be unrelated to 'Partial<R>'.

32     post(body: P | null, options: HttpEntityOptions): Observable<ODataEntity<R>>;
       ~~~~
node_modules/angular-odata/lib/resources/requests/action.d.ts:33:5 - error TS2416: Property 'post' in type 'ODataActionResource<P, R>' is not assignable to the same property in base type 'ODataResource<R>'.
  Type '{ (body: P | null, options: HttpEntityOptions): Observable<ODataEntity<R>>; (body: P | null, options: HttpEntitiesOptions): Observable<...>; (body: P | null, options: HttpPropertyOptions): Observable<...>; }' is not assignable to type '(attrs: Partial<R>, options: HttpOptions & { responseType?: "arraybuffer" | "blob" | "value" | "property" | "entity" | "entities" | undefined; withCount?: boolean | undefined; }) => Observable<...>'.

33     post(body: P | null, options: HttpEntitiesOptions): Observable<ODataEntities<R>>;
       ~~~~
node_modules/angular-odata/lib/resources/requests/action.d.ts:34:5 - error[0m TS2416: Property 'post' in type 'ODataActionResource<P, R>' is not assignable to the same property in base type 'ODataResource<R>'.
  Type '{ (body: P | null, options: HttpEntityOptions): Observable<ODataEntity<R>>; (body: P | null, options: HttpEntitiesOptions): Observable<...>; (body: P | null, options: HttpPropertyOptions): Observable<...>; }' is not assignable to type '(attrs: Partial<R>, options: HttpOptions & { responseType?: "arraybuffer" | "blob" | "value" | "property" | "entity" | "entities" | undefined; withCount?: boolean | undefined; }) => Observable<...>'.

34     post(body: P | null, options: HttpPropertyOptions): Observable<ODataProperty<R>>;

SOLUTION: Please make the following changes to the action.ts file:

...
//#region Requests
  post<P>(body: P | null, options: HttpEntityOptions): Observable<ODataEntity<R>>;
  post<P>(body: P | null, options: HttpEntitiesOptions): Observable<ODataEntities<R>>;
  post<P>(body: P | null, options: HttpPropertyOptions): Observable<ODataProperty<R>>;
  post<P>(body: P | null, options: HttpEntityOptions & HttpEntitiesOptions & HttpPropertyOptions): Observable<any> {
    return super.post(body, options);
  }
  //#endregion
...

Thank you!

diegomvh commented 3 years ago

Thank you very much for reporting this issue. I can't reproduce the build error, but it is clearly an error, the types defined for actions and functions are of the form <Parameters, Response>. And there is a contradiction between the way to call the post in the action and what the parent class expects as attrs for the post.

https://github.com/diegomvh/angular-odata/blob/036040781f4510bff399d9b99893ba7761da5e87/projects/angular-odata/src/lib/resources/resource.ts#L183

I have been thinking for some time that the values ​​that are passed to POST, PATCH and PUT are not only attributes of an entity.

Thank you again and greetings.