0

this used to work just fine in TS 2.3

getCampaigns(): Observable<List<CampaignsModelExt>> {
        return this.store.select(store => store.msDatabase.sdk.table_campaigns)
            .take(1)
    }

but with 2.4 I get an error of:

Error:(628, 9) TS2322:Type 'Observable>' is not assignable to type 'Observable>'. Type 'List' is not assignable to type 'List'. Type 'CampaignsModel' is not assignable to type 'CampaignsModelExt'. Property 'getCampaignPlaylistModeName' is missing in type 'CampaignsModel'.

so in order to fix it I have to cast it now: as Observable<List<CampaignsModelExt>>;

getCampaigns(): Observable<List<CampaignsModelExt>> {
        return this.store.select(store => store.msDatabase.sdk.table_campaigns)
            .take(1) as Observable<List<CampaignsModelExt>>;
    }

any ideas why?

and if you are wondering about my store.msDatabase.sdk.table_campaigns its typed as table_campaigns?: List<CampaignsModel>;

Thanks you,

Sean

born2net
  • 24,129
  • 22
  • 65
  • 104
  • 1
    This is most likely related to this https://stackoverflow.com/questions/44793859/rxjs-subject-d-ts-error-class-subjectt-incorrectly-extends-base-class-obs – martin Jul 17 '17 at 16:25
  • 2
    Basically, TypeScript 2.4 is more strict on generics – martin Jul 17 '17 at 16:25
  • it's a pain, why do I have to tell it again what it is returning, I already typed it as the return and it is the same :/ – born2net Jul 17 '17 at 16:28
  • 2
    They are not the same. If `getCampaigns` returned `Observable>` you would not have the problem. A `CampaignsModel` is not necessarily a `CampaignsModelExt` and that is now checked in the generics and is an error. – cartant Jul 17 '17 at 17:53
  • mmm I understand, do you mind also looking into another related Q's: https://stackoverflow.com/questions/45153925/why-is-the-new-generics-in-typescript-2-4-causing-this-to-fail – born2net Jul 17 '17 at 21:27

1 Answers1

1

Please see this question/answer, which covers roughly the same thing.

Basically, TypeScript 2.4 is far stricter when it comes to generics and Promises. You can read the release notes here that explain it.

  • tx, so I can understand this as CampaignModel is not the same as CampaignModelExt... so posted related question: https://stackoverflow.com/questions/45153925/why-is-the-new-generics-in-typescript-2-4-causing-this-to-fail – born2net Jul 17 '17 at 21:27