Skip to content

Commit 70517ea

Browse files
fix(signals): correctly infer the type of methods with generics (#4249)
1 parent 3d45e5a commit 70517ea

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

modules/signals/spec/types/signal-store.types.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,23 @@ describe('signalStore', () => {
623623
);
624624
});
625625

626+
it('correctly infers the type of methods with generics', () => {
627+
const snippet = `
628+
const Store = signalStore(
629+
withMethods(() => ({
630+
log<Str extends string>(str: Str) {
631+
console.log(str);
632+
},
633+
}))
634+
);
635+
636+
const store = inject(Store);
637+
`;
638+
639+
expectSnippet(snippet + `store.log('ngrx');`).toSucceed();
640+
expectSnippet(snippet + `store.log(10);`).toFail();
641+
});
642+
626643
describe('custom features', () => {
627644
const baseSnippet = `
628645
function withX() {

modules/signals/src/signal-store-models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export type SignalStoreProps<FeatureResult extends SignalStoreFeatureResult> =
2424

2525
export type SignalsDictionary = Record<string, Signal<unknown>>;
2626

27-
export type MethodsDictionary = Record<string, (...args: any[]) => unknown>;
27+
export type MethodsDictionary = Record<string, Function>;
2828

2929
export type SignalStoreHooks = {
3030
onInit?: () => void;

0 commit comments

Comments
 (0)