Skip to content

Instantly share code, notes, and snippets.

@yharaskrik
Created July 12, 2022 05:38
Show Gist options
  • Save yharaskrik/63a178b0561f4a867e20458f7db0d83c to your computer and use it in GitHub Desktop.
Save yharaskrik/63a178b0561f4a867e20458f7db0d83c to your computer and use it in GitHub Desktop.
component store 14.0.1 typing issue
interface SomeType {
name: string;
prop: string;
}
export abstract class MyStore<
QueryVariables extends SomeType
> extends ComponentStore<any> {
protected abstract readonly query$: Observable<Omit<QueryVariables, 'name'>>;
readonly load = this.effect(
(origin$: Observable<Omit<QueryVariables, 'name'> | null>) => origin$
);
protected constructor() {
super();
}
protected initializeLoad() {
this.load(this.query$);
}
}
@yharaskrik
Copy link
Author

Where as this works:

import { ComponentStore } from '@ngrx/component-store';
import { Observable } from 'rxjs';

interface SomeType {
  name: string;
  prop: string;
}

export abstract class MyStore<
  QueryVariables extends SomeType
> extends ComponentStore<any> {
  protected abstract readonly query$: Observable<Omit<SomeType, 'name'>>;

  readonly load = this.effect(
    (origin$: Observable<Omit<SomeType, 'name'> | null>) => origin$
  );

  protected constructor() {
    super();
  }

  protected initializeLoad() {
    this.load(this.query$);
  }
}

If I use the type directly instead of the generic to type the observable it passes type checking totally fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment