Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(component-store): effect handles generics that extend upon a type #3485

Merged
merged 2 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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