Skip to content

Commit

Permalink
fix(signals): correctly infer the type of methods with generics
Browse files Browse the repository at this point in the history
  • Loading branch information
markostanimirovic committed Feb 17, 2024
1 parent 4b310dd commit 92cdeda
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions modules/signals/spec/types/signal-store.types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,23 @@ describe('signalStore', () => {
);
});

it('correctly infers the type of methods with generics', () => {
const snippet = `
const Store = signalStore(
withMethods(() => ({
log<Str extends string>(str: Str) {
console.log(str);
},
}))
);
const store = inject(Store);
`;

expectSnippet(snippet + `store.log('ngrx');`).toSucceed();
expectSnippet(snippet + `store.log(10);`).toFail();
});

describe('custom features', () => {
const baseSnippet = `
function withX() {
Expand Down
2 changes: 1 addition & 1 deletion modules/signals/src/signal-store-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type SignalStoreProps<FeatureResult extends SignalStoreFeatureResult> =

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

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

export type SignalStoreHooks = {
onInit?: () => void;
Expand Down

0 comments on commit 92cdeda

Please sign in to comment.