Skip to content

Conversation

kajetansw
Copy link
Member

@kajetansw kajetansw commented Aug 3, 2020

Issue

The goal of this PR is to fix #177. As provided by the author within his playground demo, selectSlice incorrectly infers the type of a slice when the type provided to RxState declaration is not a concrete type but a generic subtype of one.

Example

To verify if the selectSlice does what it is supposed to, I created a small example that can be played with even inside our own RxAngular repo.

interface MyState {
  title: string;
  items: string[];
  panelOpen: boolean;
}

const state$: Observable<MyState> = of({
  items: [''],
  panelOpen: true,
  title: 'dwadaw'
});

// typical use-case, `data` should be of the correct type
const slice$ = state$.pipe(
  selectSlice(['items'])
).subscribe(data => data.items);

// example from christianacca reproduced, simplified
class AppComp<T extends MyState> {
  constructor(protected state: RxState<T>) {
    const a = this.state.select().pipe(
      selectSlice(['title']),
      filter(({ title }) => true)
    );
  }
}

When verifying, please do it also for strictNullChecks compiler options set to false. The most problems with type inference come up with this option.

@BioPhoton BioPhoton added the { } State @rx-angular/state related label Aug 9, 2020
@BioPhoton BioPhoton mentioned this pull request Aug 9, 2020
5 tasks
@BioPhoton BioPhoton merged commit c0bd296 into rx-angular:master Aug 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

{ } State @rx-angular/state related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

selectSlice still a problem?

2 participants