Skip to content

Commit

Permalink
fix(component-store): effect handles generics that extend upon a type (
Browse files Browse the repository at this point in the history
…#3485)

Closes #3482
  • Loading branch information
timdeschryver committed Jul 12, 2022
1 parent 8219b1d commit 9d2bda7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
44 changes: 44 additions & 0 deletions modules/component-store/spec/types/regression.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { expecter } from 'ts-snippet';
import { compilerOptions } from './utils';

describe('regression component-store', () => {
const expectSnippet = expecter(
(code) => `
import { ComponentStore } from '@ngrx/component-store';
import { of, EMPTY, Observable } from 'rxjs';
import { concatMap } from 'rxjs/operators';
${code}
`,
compilerOptions()
);

it('https://github.com/ngrx/platform/issues/3482', () => {
const effectTest = `
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 should work
this.load(this.query$);
}
}
`;
expectSnippet(effectTest).toSucceed();
});
});
4 changes: 3 additions & 1 deletion modules/component-store/src/component-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ export class ComponentStore<T extends object> implements OnDestroy {
ObservableType = OriginType extends Observable<infer A> ? A : never,
// Return either an optional callback or a function requiring specific types as inputs
ReturnType = ProvidedType | ObservableType extends void
? (observableOrValue?: void | Observable<void>) => Subscription
? (
observableOrValue?: ObservableType | Observable<ObservableType>
) => Subscription
: (
observableOrValue: ObservableType | Observable<ObservableType>
) => Subscription
Expand Down

0 comments on commit 9d2bda7

Please sign in to comment.