diff --git a/modules/component-store/spec/types/regression.spec.ts b/modules/component-store/spec/types/regression.spec.ts new file mode 100644 index 0000000000..d0ebacd747 --- /dev/null +++ b/modules/component-store/spec/types/regression.spec.ts @@ -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 { + protected abstract readonly query$: Observable>; + + readonly load = this.effect( + (origin$: Observable | null>) => origin$ + ); + + protected constructor() { + super(); + } + + protected initializeLoad() { + // 👇 this should work + this.load(this.query$); + } + } + `; + expectSnippet(effectTest).toSucceed(); + }); +}); diff --git a/modules/component-store/src/component-store.ts b/modules/component-store/src/component-store.ts index 8af8cb6b92..6f2b1a02ab 100644 --- a/modules/component-store/src/component-store.ts +++ b/modules/component-store/src/component-store.ts @@ -291,7 +291,9 @@ export class ComponentStore implements OnDestroy { ObservableType = OriginType extends Observable ? A : never, // Return either an optional callback or a function requiring specific types as inputs ReturnType = ProvidedType | ObservableType extends void - ? (observableOrValue?: void | Observable) => Subscription + ? ( + observableOrValue?: ObservableType | Observable + ) => Subscription : ( observableOrValue: ObservableType | Observable ) => Subscription