angelnikolov / ts-cacheable

Observable/Promise Cache Decorator
https://npmjs.com/package/ts-cacheable
ISC License
340 stars 42 forks source link

Compilation error when trying to use #1

Closed tleveque23 closed 6 years ago

tleveque23 commented 6 years ago

As soon as I try to use the option "cacheBusterObserver" in the @Cacheable() decorator, I get a compilation error:

error TS2345: Argument of type '{ cacheBusterObserver: Subject<{}>; }' is not assignable to parameter of type 'ICacheConfig'.
  Types of property 'cacheBusterObserver' are incompatible.
    Type 'Subject<{}>' is not assignable to type 'Observable<void>'.
      Property 'source' is protected but type 'Observable<T>' is not a class derived from 'Observable<T>'.

I have a constant declared with the right name (const productNotifier = new Subject();) in my file.

Note: It is working fine if I just use the plain @Cacheable() without any options. Note #2: If when it is working fine without the option (using ng serve), I add the option and the Subject and save, I see the compilation error but it says "Compiled successfully" and the code actually work fine! But if I stop ng serve and try to start it again, then it fail....

I am using: angular 5.2.10 rxjs 5.5.10 zone 0.8.26 typescript 2.6.2

tleveque23 commented 6 years ago

I just created a very basic application that replicate the bug: https://github.com/tleveque23/cacheablebug

Just try to run ng serve with it.

angelnikolov commented 6 years ago

Thanks for report @tleveque23. The cacheable decorator is still using RxJs 5.5. Upgrading that to 6.0.0 will fix it. Gonna fix this soon!

angelnikolov commented 6 years ago

@tleveque23 I published 1.0.2 which includes a fix for your issue + bumping up RxJs version to 6.2.0. Hope that resolved your issue!

katyapavlenko commented 4 years ago

Hi, @angelnikolov

experiencing same problem now "rxjs": "6.5.4" "ngx-cacheable": "1.4.1"

const buster$ = new Subject<void>()

@Cacheable({ cacheBusterObserver: buster$.asObservable() })
private get data(): string {return 'somestring'}
error TS2345: Argument of type 'TypedPropertyDescriptor<string>' is not assignable to parameter of type 'TypedPropertyDescriptor<ICacheable<Observable<any>>>'.
Type 'string' is not assignable to type 'ICacheable<Observable<any>>'.
angelnikolov commented 4 years ago

The method needs to return an Observable. :)

katyapavlenko commented 4 years ago

Oh no! :) Maybe its better to add return type to methods in documentation to prevent further mistakes like mine?

Also is it going to be implemented for scalar values in the future?

P.S. thank you for the fas answer!

angelnikolov commented 4 years ago

Yes, adding return types makes sense. Will add to my list. :) About scalar values, I haven't thought about that, but we already have decorators for that like memo. https://www.npmjs.com/package/memo-decorator If there's demand I can add it in, but I can't say when.